Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4901
Dp1 [I] [J] is the number of I-participating, exclusive OR value J, x1 [I] [J] is the number of different or values from the position I forward to the position 1 as J. dp2 [I] [J] is an I-participated, the value is the number of J, and the value of X2 [I] [J] is the number of J from the position I to the position n.
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define ll __int64 5 using namespace std; 6 const int mod=1000000007; 7 8 ll dp1[1100][1100]; 9 ll dp2[1100][1100];10 ll x1[1100][1100];11 ll x2[1100][1100];12 int t,n;13 int c[1100];14 15 int main()16 {17 scanf("%d",&t);18 while(t--)19 {20 scanf("%d",&n);21 for(int i=1; i<=n; i++)22 {23 scanf("%d",&c[i]);24 }25 memset(dp1,0,sizeof(dp1));26 memset(dp2,0,sizeof(dp2));27 memset(x1,0,sizeof(x1));28 memset(x2,0,sizeof(x2));29 for(int i=1; i<=n; i++)30 {31 for(int j=0; j<=1024; j++)32 {33 int m=j^c[i];34 dp1[i][m]=(dp1[i][m]+x1[i-1][j])%mod;35 }36 dp1[i][c[i]]=(dp1[i][c[i]]+1)%mod;37 for(int j=0; j<=1024; j++)38 {39 x1[i][j]=(x1[i-1][j]+dp1[i][j])%mod;40 }41 }42 for(int i=n; i>=1; i--)43 {44 for(int j=0; j<=1024; j++)45 {46 int m=j&c[i];47 dp2[i][m]=(dp2[i][m]+x2[i+1][j])%mod;48 }49 dp2[i][c[i]]=(dp2[i][c[i]]+1)%mod;50 for(int j=0; j<=1024; j++)51 {52 x2[i][j]=(x2[i+1][j]+dp2[i][j])%mod;53 }54 }55 ll ans=0,sum;56 for(int i=1; i<=n-1; i++)57 {58 for(int j=0; j<=1024; j++)59 {60 sum=(dp1[i][j]*x2[i+1][j])%mod;61 ans=(ans+sum)%mod;62 }63 }64 printf("%I64d\n",ans);65 }66 return 0;67 }
View code