UVa12063 Zeros and Ones

神坑 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\n", cas, dp(n, k));
52     }
53     
54     return 0;
55 }
View Code

 

转载于:https://www.cnblogs.com/showson/p/5111901.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值