• 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
    ", cas, dp(n, k));
    52     }
    53     
    54     return 0;
    55 }
    View Code
  • 相关阅读:
    6、方法
    5、封装
    4、循环
    3、判断
    2、基本语法
    1、基本框架
    CodeForces 681C Heap Operations(模拟)
    CodeForces 682C Alyona and the Tree(广搜 + 技巧)
    URAL 2099 Space Invader题解 (计算几何)
    HDU 5833 (2016大学生网络预选赛) Zhu and 772002(高斯消元求齐次方程的秩)
  • 原文地址:https://www.cnblogs.com/showson/p/5111901.html
Copyright © 2020-2023  润新知