标签:
2 3 1 2 3 4 1 2 3 3
1 4
1 #include <bits/stdc++.h> 2 using LL = long long; 3 using namespace std; 4 const int maxn = 1010; 5 const LL mod = 1e9 + 7; 6 LL dp[maxn][1024][2],dp2[maxn][1024]; 7 int n,a[maxn]; 8 int main(){ 9 int kase; 10 scanf("%d",&kase); 11 while(kase--){ 12 memset(dp,0,sizeof dp); 13 memset(dp2,0,sizeof dp2); 14 scanf("%d",&n); 15 for(int i = 1; i <= n; ++i) scanf("%d",a + i); 16 dp[1][a[1]][1] = 1; 17 for(int i = 2; i <= n; ++i){ 18 dp[i][a[i]][1]++; 19 for(int j = 0; j < 1024; ++j){ 20 dp[i][j][0] += dp[i-1][j][0] + dp[i-1][j][1]; 21 dp[i][j^a[i]][1] += dp[i-1][j][0] + dp[i-1][j][1]; 22 dp[i][j][0] %= mod; 23 dp[i][j^a[i]][1] %= mod; 24 } 25 } 26 dp2[n][a[n]] = 1; 27 for(int i = n-1; i > 0; --i){ 28 dp2[i][a[i]]++; 29 for(int j = 0; j < 1024; ++j){ 30 dp2[i][j] += dp2[i+1][j]; 31 dp2[i][j&a[i]] += dp2[i+1][j]; 32 dp2[i][j] %= mod; 33 dp2[i][j&a[i]] %= mod; 34 } 35 } 36 LL ret = 0; 37 for(int i = 1; i < n; ++i) 38 for(int j = 0; j < 1024; ++j) 39 ret = (ret + dp[i][j][1]*dp2[i+1][j])%mod; 40 printf("%I64d\n",ret); 41 } 42 return 0; 43 }
标签:
原文地址:http://www.cnblogs.com/crackpotisback/p/4901401.html