HDU 5119 背包
题意:告诉n个数字,在其中选择0~n个数字,异或,然后求得到的结果不小于m的个数。
分析:超了int,本来说的是枚举,后来大姐头自己变成了背包DP。牛牪犇!!!
1 #include <cstdio>
2 #include <iostream>
3 #include <sstream>
4 #include <cmath>
5 #include <cstring>
6 #include <cstdlib>
7 #include <string>
8 #include <vector>
9 #include <map>
10 #include <set>
11 #include <queue>
12 #include <stack>
13 #include <algorithm>
14 using namespace std;
15 #define ll long long
16 #define _cle(m, a) memset(m, a, sizeof(m))
17 #define repu(i, a, b) for(int i = a; i < b; i++)
18 #define repd(i, a, b) for(int i = b; i >= a; i--)
19 #define sfi(n) scanf("%d", &n)
20 #define pfi(n) printf("%d\n", n)
21 #define N 1000010
22 #define M 25
23 ll dp[N][2];
24 int main()
25 {
26 int T;
27 sfi(T);
28 repu(kase, 1, T + 1)
29 {
30 _cle(dp, 0);
31 int n, m;
32 sfi(n), sfi(m);
33 int x;
34 int flag = 0;
35 int maxn = 0;
36 dp[0][1] = 1;
37 repu(i, 0, n)
38 {
39 sfi(x);
40 int tmaxn = maxn;
41 repu(j, 0, maxn + 1)
42 dp[j][flag] = dp[j][!flag];
43 repu(j, 0, maxn + 1)
44 {
45 int t = x ^ j;
46 dp[t][flag] += dp[j][!flag];
47 tmaxn = max(t, tmaxn);
48 }
49 maxn = tmaxn;
50 flag = !flag;
51 }
52 ll sum = 0;
53 repu(i, m, maxn + 1)
54 {
55 sum += dp[i][!flag];
56 }
57 printf("Case #%d: %I64d\n", kase, sum);
58 }
59 return 0;
60 }
人生就像心电图,想要一帆风顺,除非game-over