HDU 4901 - The Romantic Hero

dpdp,需要绕一个弯子,注意不要重复计数,然后就没什么了。

 1 /*
 2 ID:esxgx1
 3 LANG:C++
 4 PROG:hdu4901
 5 */
 6 #include <cstdio>
 7 #include <cstring>
 8 #include <iostream>
 9 #include <algorithm>
10 using namespace std;
11 
12 const int mod = 1e9 + 7;
13 
14 unsigned _dp[1007][1024][2], (*dp)[1024][2] = &_dp[1];
15 unsigned dp2[1024];
16 int a[1007];
17 
18 int main(void)
19 {
20     #ifndef ONLINE_JUDGE
21     freopen("in.txt", "r", stdin);
22     #endif
23 
24     int T;
25     scanf("%d", &T);
26     for(int t=1; t<=T; ++t) {
27         int N;
28         scanf("%d", &N);
29         for(int i=0; i<N; ++i)
30             scanf("%u", &a[i]);
31         for(int i=0; i<N; ++i) {
32             for(int j=0; j<1024; ++j) {
33                 dp[i][j][0] = dp[i-1][j ^ a[i]][1];
34                 dp[i][j][1] = (dp[i][j][0] + dp[i-1][j][1]) % mod;
35             }
36             dp[i][a[i]][0] = (dp[i][a[i]][0] + 1) % mod;
37             dp[i][a[i]][1] = (dp[i][a[i]][1] + 1) % mod;
38         }
39         unsigned ans = 0;
40         memset(dp2,0, sizeof(dp2));
41         for(int i=N; i--; ) {
42             for(int j=0; j<1024; ++j) {
43                 ans = (ans + (((long long)dp2[j] * dp[i][j][0]) % mod)) % mod;
44                 dp2[j & a[i]] = (dp2[j & a[i]] + dp2[j]) % mod;
45             }
46             dp2[a[i]] = (dp2[a[i]] + 1) % mod;
47         }
48         printf("%u\n", ans);
49     }
50     return 0;
51 }

 

2014-10-04 13:19:54 Accepted 4901 1046MS 8332K 1081 B G++
posted @ 2014-10-04 13:42  e0e1e  阅读(450)  评论(0编辑  收藏  举报