• UESTC-878


    中文题

    我是传送门

    我们定义dp[i][j][k]为利用前i张牌使两个人的分数分别为j和k的方案数

    需要注意的就是数组的大小而已。一开始没有想清楚,看到牌的大小不超过100,以为得分也不会超过一百...其实异或后可能出现得分二进制表示为1111111的情况

    别忘了初始化。双方都不拿也是一种情况,dp[0][0][0] = 1。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <algorithm>
     5 #include <queue>
     6 #include <vector>
     7 #define max(x, y) (x > y ? x : y)
     8 #define min(x, y) (x > y ? y : x)
     9 #define INF 0x3f3f3f3f
    10 #define mod 1000000007
    11 #define Yes printf("Yes
    ")
    12 #define No printf("No
    ")
    13 typedef long long LL;
    14 using namespace std;
    15 
    16 int maxn;
    17 int v[20];
    18 int dp[20][200][200];
    19 int n;
    20 int main(int argc, const char * argv[]) {
    21     scanf("%d", &n);
    22     maxn = -INF;
    23     for (int i = 1; i <= n; i++) {
    24         scanf("%d", &v[i]);
    25         maxn = max(maxn, v[i]);
    26     }
    27     dp[0][0][0] = 1;
    28     for (int i = 1; i <= n; i++) {
    29         for (int k = 0; k <= 128; k++) {
    30             for (int j = 0; j <= 128; j++) {
    31                 dp[i][k][j] += dp[i - 1][k][j];
    32                 dp[i][k ^ v[i]][j] += dp[i - 1][k][j];
    33                 dp[i][k][j ^ v[i]] += dp[i - 1][k][j]; 
    34             }
    35         }
    36     }
    37     LL ans = 0;
    38     for (int i = 0; i <= 128; i++) {
    39         for (int j = i; j <= 128; j++) {
    40             ans += dp[n][i][j];
    41         }
    42     } 
    43     printf("%lld
    ", ans);
    44     return 0;
    45 }
  • 相关阅读:
    资源与锁
    资源与锁
    Leetcode-Rotate List
    Leetcode-Unique Paths II
    Leetcode-Unique Paths
    Leetcode-Minimum Path Sum
    Leetcode-Sqrt(x)
    Leetcode-Set Matrix Zeroes
    Leetcode-Search a 2D Matrix
    Leetcode-Combinations
  • 原文地址:https://www.cnblogs.com/xFANx/p/7260030.html
Copyright © 2020-2023  润新知