Give you n numbers and ask you to divide the number into two arrays. the requirements of all elements in S, T, and t are larger than those in S, ask how many types of conditions are there when all elements in s perform the XOR operation and all the elements in T perform the & operation value equal.
DP backpack ideas
DPA [I] [J] [0] indicates the number of solutions starting from left to I, where I is not obtained and the status is J.
DPA [I] [J] [1] indicates the number of solutions from job start to I, from I to status J.
DPB [I] [J] indicates the number of solutions in the status of J from right to I.
Because the s set must be on the left of the t set, the split lines of the set can be enumerated, and the enumeration scheme must be unique, just make sure that the points on the split line are forcibly obtained. In the final calculation, DPA [I] [J] [1] is used to force the left side to obtain the split line.
#include "stdio.h"#include "string.h"__int64 mod=1000000007;__int64 dpa[1010][1025][2],dpb[1010][1025],a[1010];int main(){ int Case,n,i,j; __int64 ans; scanf("%d",&Case); while (Case--) { scanf("%d",&n); for (i=1;i<=n;i++) scanf("%I64d",&a[i]); memset(dpa,0,sizeof(dpa)); memset(dpb,0,sizeof(dpb)); dpa[1][a[1]][1]=1; for (i=2;i<=n;i++) { dpa[i][a[i]][1]++; for (j=0;j<1024;j++) { dpa[i][j][0]+=(dpa[i-1][j][0]+dpa[i-1][j][1])%mod; if (dpa[i][j][0]>mod) dpa[i][j][0]-=mod; dpa[i][j^a[i]][1]+=(dpa[i-1][j][1]+dpa[i-1][j][0])%mod; if (dpa[i][j^a[i]][1]>mod) dpa[i][j^a[i]][1]-=mod; } } dpb[n][a[n]]=1; for (i=n-1;i>=1;i--) { dpb[i][a[i]]++; for (j=0;j<1024;j++) { dpb[i][j&a[i]]+=dpb[i+1][j]; if (dpb[i][j&a[i]]>mod) dpb[i][j&a[i]]-=mod; dpb[i][j]+=dpb[i+1][j]; if (dpb[i][j]>mod) dpb[i][j]-=mod; } } ans=0; for (i=1;i<n;i++) for (j=0;j<=1024;j++) { ans+=(dpa[i][j][1]*dpb[i+1][j])%mod; if (ans>mod)ans-=mod; } printf("%I64d\n",ans); } return 0;}