This commit is contained in:
Zengtudor 2024-10-09 12:36:38 +08:00
parent 48ad276a56
commit 82db0d1178

View File

@ -1,11 +1,19 @@
#define NDEBUG
#include <cctype> #include <cctype>
#include <iostream> #include <iostream>
#include <algorithm> #include <algorithm>
#include <type_traits> #include <type_traits>
#define NV(v)#v<<" : "<<(v)
#ifdef NDEBUG
#define DEBUG(code)
#else
#define DEBUG(code){code}
#endif
using ull = unsigned long long; using ull = unsigned long long;
static const size_t max_n {(size_t)2e3+5}; static const size_t max_n {(size_t)2e3+5};
// static const size_t max_n {(size_t)10};
static ull k, c[max_n][max_n], prefix[max_n][max_n], t, n, m; static ull k, c[max_n][max_n], prefix[max_n][max_n], t, n, m;
static void init(){ static void init(){
@ -16,16 +24,32 @@ static void init(){
c[i][j] = (c[i-1][j-1] + c[i-1][j])%k; c[i][j] = (c[i-1][j-1] + c[i-1][j])%k;
} }
} }
DEBUG(
for(ull i{0};i<max_n;i++){
for(ull j{0};j<=i;j++){
std::cout<<c[i][j]<<' ';
}
std::cout<<'\n';
}
std::cout<<"===========\n";
)
for(ull i = 2;i<max_n-1;i++){ //注意这里是max_n-1 for(ull i = 2;i<max_n-1;i++){ //注意这里是max_n-1
for(ull j{1};j<=i;j++){ 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][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]; prefix[i][i+1] = prefix[i][i];
} }
DEBUG(
for(ull i{0};i<max_n;i++){
for(ull j{0};j<=i;j++){
std::cout<<prefix[i][j]<<' ';
}
std::cout<<'\n';
}
)
} }
#define NV(v)#v<<" : "<<(v)
template<class T> template<class T>
struct ReadNumber{ struct ReadNumber{
ReadNumber& operator>>(T &num){ ReadNumber& operator>>(T &num){