官方题解:http://blog.sina.com.cn/s/blog_6bddecdc0102uytw.html
每一步都要mod,浪费了220分钟。
1 #include<cstdio> 2 #include<cstring> 3 #define mt(a,b) memset(a,b,sizeof(a)) 4 typedef __int64 LL; 5 const int mod=1000000007; 6 const int M=1024; 7 int a[M]; 8 LL dpxor[M][M],dpand[M][M]; 9 int main(){ 10 int t,n; 11 while(~scanf("%d",&t)){ 12 while(t--){ 13 scanf("%d",&n); 14 for(int i=1;i<=n;i++){ 15 scanf("%d",&a[i]); 16 } 17 mt(dpxor,0); 18 mt(dpand,0); 19 for(int i=1;i<=n;i++){ 20 dpxor[i][a[i]]=1; 21 for(int j=0;j<M;j++){ 22 dpxor[i][j^a[i]]+=dpxor[i-1][j]; 23 dpxor[i][j^a[i]]%=mod; 24 dpxor[i][j]+=dpxor[i-1][j]; 25 dpxor[i][j]%=mod; 26 } 27 } 28 for(int i=n;i>=1;i--){ 29 dpand[i][a[i]]=1; 30 for(int j=0;j<M;j++){ 31 dpand[i][j&a[i]]+=dpand[i+1][j]; 32 dpand[i][j&a[i]]%=mod; 33 dpand[i][j]+=dpand[i+1][j]; 34 dpand[i][j]%=mod; 35 } 36 } 37 LL ans=0; 38 for(int i=1;i<=n;i++){ 39 for(int j=0;j<M;j++){ 40 ans+=((dpxor[i][j]+mod-dpxor[i-1][j])%mod)*dpand[i+1][j]; 41 ans%=mod; 42 } 43 } 44 printf("%I64d\n",ans); 45 } 46 } 47 return 0; 48 }