This commit is contained in:
Zengtudor 2024-10-09 00:29:06 +08:00
parent 13df10d599
commit d97eb12ac3
2 changed files with 79 additions and 0 deletions

64
src/P2822/P2822_debug.cpp Normal file
View File

@ -0,0 +1,64 @@
#include <cctype>
#include <iostream>
#include <algorithm>
#include <type_traits>
using ull = unsigned long long;
static const size_t max_n {(size_t)2e3+5};
ull k, c[max_n][max_n], prefix[max_n][max_n], t, n, m;
static void init(){
c[0][0] = c[1][0] = c[1][1] = 1;
for(ull i {2};i<max_n;i++){
c[i][0]=1;
for(ull j{1};j<=i;j++){
c[i][j] = (c[i-1][j-1] + c[i-1][j])%k;
}
}
for(ull i = 2;i<max_n;i++){ //t被修改
for(ull j{1};j<=i;j++){
prefix[i][j] = prefix[i-1][j]+prefix[i][j-1]-prefix[i-1][j-1] + (c[i][j]==0?1:0);
}
// prefix[i][i+1] = prefix[i][i];
}
}
#define NV(v)#v<<" : "<<(v)
template<class T>
struct ReadNumber{
ReadNumber& operator>>(T &num){
c=0,w=1,n=0;
while(!isdigit(c)){
if constexpr (!std::is_unsigned_v<T>){
if(c=='-')w=-1;
}
c=getchar();
}
while(isdigit(c)){
n=n*10+(c-'0');
c=getchar();
}
num = w*n;
return *this;
}
private:
char c;
T w,n;
};
ReadNumber<ull> readull;
int main(){
readull>>t>>k;
// std::cout<<NV(t)<<'\n'<<NV(k)<<'\n';
init();
for(ull i {0};i<t;i++){
// std::cout<<NV(t)<<'\n'<<NV(k)<<'\n';
readull>>n>>m;
// std::cout<<"test\n";
m = std::min(m,n);
std::cout<<(prefix[n][m])<<'\n';
}
}

15
src/test.cpp Normal file
View File

@ -0,0 +1,15 @@
#include <iostream>
using ull = unsigned long long;
ull t;
#define NV(v)#v<<" : "<<(v)
int main(){
std::iostream::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);
std::cout<<NV(t)<<'\n';
std::cin>>t;
std::cout<<NV(t)<<'\n';
}