标签:dp
2 3 2 1 2 3 3 3 1 2 3
Case #1: 4 Case #2: 2HintIn the ?rst sample, Matt can win by selecting: friend with number 1 and friend with number 2. The xor sum is 3. friend with number 1 and friend with number 3. The xor sum is 2. friend with number 2. The xor sum is 2. friend with number 3. The xor sum is 3. Hence, the answer is 4.
#include <map> #include <set> #include <list> #include <queue> #include <stack> #include <vector> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace std; __int64 dp[2][1 << 22]; int num[44]; int main() { int t, n, m, icase = 1; __int64 ans; scanf("%d", &t); while (t--) { memset (dp, 0, sizeof(dp)); scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) { scanf("%d", &num[i]); } dp[0][0] = 1; for (int i = 1; i <= n; ++i) { for (int j = 0; j <= (1 << 20); ++j) { dp[i % 2][j] = dp[1 - (i % 2)][j] + dp[1 - (i % 2)][j ^ num[i]]; } } ans = 0; for (int i = m; i <= (1 << 20); ++i) { ans += dp[n % 2][i]; } printf("Case #%d: %I64d\n", icase++, ans); } return 0; }
标签:dp
原文地址:http://blog.csdn.net/guard_mine/article/details/41621795