神坑 1竟然还要取模
在后面填数多好的
1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 #include<algorithm> 5 #include<iostream> 6 7 using namespace std; 8 9 void setIO(const string& s) { 10 freopen((s + ".in").c_str(), "r", stdin); 11 freopen((s + ".out").c_str(), "w", stdout); 12 } 13 template<typename Q> Q read(Q& x) { 14 static char c, f; 15 for(f = 0; c = getchar(), !isdigit(c); ) if(c == '-') f = 1; 16 for(x = 0; isdigit(c); c = getchar()) x = x * 10 + c - '0'; 17 if(f) x = -x; 18 return x; 19 } 20 template<typename Q> Q read() { 21 static Q x; return read(x); 22 } 23 24 typedef long long LL; 25 LL f[65][65][101]; 26 27 LL dp(int n, int p) { 28 if(!p || (n & 1)) return 0; 29 memset(f, 0, sizeof f); 30 f[1][1][1 % p] = 1; 31 for(int i = 1; i < n; i++) { 32 for(int j = 0; j <= i; j++) { 33 for(int k = 0; k < p; k++) { 34 f[i + 1][j][(k << 1) % p] += f[i][j][k]; 35 f[i + 1][j + 1][(k << 1 | 1) % p] += f[i][j][k]; 36 } 37 } 38 } 39 return f[n][n / 2][0]; 40 } 41 42 int main() { 43 #ifdef DEBUG 44 freopen("in.txt", "r", stdin); 45 freopen("out.txt", "w", stdout); 46 #endif 47 48 int T = read<int>(), n, k; 49 for(int cas = 1; cas <= T; cas++) { 50 read(n), read(k); 51 printf("Case %d: %lld ", cas, dp(n, k)); 52 } 53 54 return 0; 55 }