zoukankan      html  css  js  c++  java
  • UESTC

    http://acm.uestc.edu.cn/#/problem/show/878

    设dp[i][j][k]表示在前i个数中,第一个得到的异或值是j,第二个人得到的异或值是k的方案数有多少种。

    因为异或后的大小不确定,所以不能压缩数组,但是也不大。。可以过。

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <assert.h>
    #define IOS ios::sync_with_stdio(false)
    using namespace std;
    #define inf (0x3f3f3f3f)
    typedef long long int LL;
    
    
    #include <iostream>
    #include <sstream>
    #include <vector>
    #include <set>
    #include <map>
    #include <queue>
    #include <string>
    #include <bitset>
    const int maxn = 1e2 + 20;
    int a[maxn], n;
    int ans;
    int dp[20][500 + 20][500 + 20];
    void work() {
        ans = 0;
        for (int i = 1; i <= n; ++i) {
            scanf("%d", &a[i]);
        }
        dp[0][0][0] = true;
        for (int i = 1; i <= n; ++i) {
            for (int j = 0; j <= 500; ++j) {
                for (int k = 0; k <= 500; ++k) {
                    if (dp[i - 1][j][k]) {
                        dp[i][j][k] += dp[i - 1][j][k];
                        dp[i][j ^ a[i]][k] += dp[i - 1][j][k];
                        dp[i][j][k ^ a[i]] += dp[i - 1][j][k];
    //                    if (j <= k) ans++;
                    }
                }
            }
        }
        for (int i = 0; i <= 500; ++i) {
            for (int j = 0; j <= 500; ++j) {
                if (dp[n][i][j] && i <= j) {
                    ans += dp[n][i][j];
                }
            }
        }
        cout << ans << endl;
    }
    
    int main() {
    #ifdef local
        freopen("data.txt", "r", stdin);
    //    freopen("data.txt", "w", stdout);
    #endif
        while (scanf("%d", &n) != EOF) work();
        return 0;
    }
    View Code
  • 相关阅读:
    扫描线与悬线
    随机搜索与模拟退火
    树的直径相关
    分数规划及斜率优化
    数学-剩余系
    后缀数据结构
    AC自动机和KMP
    生命游戏和随机数之间某种不可言说的秘密
    转移了
    BZOJ 1710: [Usaco2007 Open]Cheappal 廉价回文
  • 原文地址:https://www.cnblogs.com/liuweimingcprogram/p/6457888.html
Copyright © 2011-2022 走看看