标签:art 大小 lin sed type ble closed assert ons
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; }
标签:art 大小 lin sed type ble closed assert ons
原文地址:http://www.cnblogs.com/liuweimingcprogram/p/6457888.html