原题链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4762
mark一下,有空要好好弄懂
#include<cstdio> #include<algorithm> using namespace std; int read_p,read_ca; inline int read(){ read_p=0;read_ca=getchar(); while(read_ca<‘0‘||read_ca>‘9‘) read_ca=getchar(); while(read_ca>=‘0‘&&read_ca<=‘9‘) read_p=read_p*10+read_ca-48,read_ca=getchar(); return read_p; } const int MOD=1e9+7; int n,a,mmh[2][1024][1024]; inline void M(int &x){while(x>=MOD)x-=MOD;while(x<0)x+=MOD;} int main(){ register int i,j,k; n=read();mmh[0][0][0]=1; for (i=1;i<=n;i++){ a=1023-read(); for (j=0;j<1024;j++) for (k=j;;k=(k-1)&j){ mmh[i&1][j][k]=mmh[i&1^1][j][k]; if (!k) break; } for (j=0;j<1024;j++) for (k=j;;k=(k-1)&j){ M(mmh[i&1][j|a][k^(k&a)]+=mmh[i&1^1][j][k]); M(mmh[i&1][j|a][(k^(k&a))|(a^(j&a))]-=mmh[i&1^1][j][k]); if (!k) break; } } printf("%d\n",mmh[n&1][1023][0]); }
时间: 2024-10-14 01:39:31