1 solutions
-
0
/* * __----~~~~~~~~~~~------___ * . . ~~//====...... __--~ ~~ * -. \_|// |||\\ ~~~~~~::::... /~ * ___-==_ _-~o~ \/ ||| \\ _/~~- * __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ * _-~~ .=~ | \\-_ '-~7 /- / || \ / * .~ .~ | \\ -_ / /- / || \ / * / ____ / | \\ ~-_/ /|- _/ .|| \ / * |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ * ' ~-| /| |-~\~~ __--~~ * |-~~-_/ | | ~\_ _-~ /\ * / \ \__ \/~ \__ * _--~ _/ | .-~~____--~-/ ~~==. * ((->/~ '.|||' -_| ~~-/ , . _|| * -_ ~\ ~~---l__i__i__i--~~_/ * _-~-__ ~) \--______________--~~ * //.-~~~-~_--~- |-------~~~~~~~~ * //.-~~~--\ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * 神兽保佑 永无BUG */ /* * @Description: I want to be the weakest vegetable in the world! * @Author: I.Z. */ #include<bits/stdc++.h> using namespace std; #define MOD 1000000007 #define pii pair<int,int> #define all(v) v.begin(),v.end() #define pb push_back #define REP(i,b,e) for(int i=(b);i<(int)(e);++i) #define over(x) {cout<<(x)<<endl;return;} #define lowbit(x) ((x)&(-(x))) #define cntbit(x) __builtin_popcount(x) #define deal(v) sort(all(v));v.erase(unique(v.begin(),v.end()),v.end()) #define lbound(v,x) lower_bound(all(v),x)-v.begin() mt19937 sd(random_device{}()); int qpow(int a,int b,int m=MOD,int res=1){ a%=m; while(b>0)res=(b&1)?(res*a%m):(res),a=a*a%m,b>>=1; return res; } int exgcd(int x,int y,int &a,int &b){ if(y==0){ a=1;b=0; return x; } int d=exgcd(y,x%y,a,b); int z=b; b=a-b*(x/y); a=z; return d; } int _x_,_y_; inline int inverse(int x,int y=MOD){ exgcd(x,y,_x_,_y_); return (_x_+y)%y; } int fac[2000005],inv[2000005]; void init(int n){ fac[0]=inv[0]=1; REP(i,1,n+1)fac[i]=fac[i-1]*i%MOD; inv[n]=qpow(fac[n],MOD-2); for(int i=n-1;i>=1;--i)inv[i]=inv[i+1]*(i+1)%MOD; } int binom(int x,int y){ return x<y||y<0? 0:fac[x]*inv[y]%MOD*inv[x-y]%MOD; } int n,m; int a[105]; int f[105][20000]; int p3[15]={1,3,9,27,81,243,729,2187,6561,19683}; int getpos1[20000],getpos0[20000]; int g[20000][2];//是否有过 sp 了? inline int getbit(int x,int y){return (x/p3[y])%3;} void Main() { cin>>n; REP(i,0,n)cin>>a[i]; m=__lg(*max_element(a,a+n))+1; REP(i,0,n)a[i]^=(1<<m)-1; REP(i,0,p3[m])f[0][i]=0; f[0][0]=1; REP(i,0,n){ REP(j,0,p3[m])f[i+1][j]=f[i][j]; REP(j,0,p3[m])REP(l,0,2)g[j][l]=0; REP(j,0,p3[m])if(f[i][j]&&!(a[i]&getpos1[j])){ if(getpos0[j]&a[i]){ g[j][0]=MOD-f[i][j]; } } REP(j,0,m)if((a[i]>>j)&1){ REP(k,0,p3[m])if(getbit(k,j)==0){ REP(l,0,2)if(g[k][l]){ (g[k+p3[j]][1]+=MOD-g[k][l])%=MOD;//每一个 sp 都要乘 -1 (g[k+p3[j]*2][l]+=g[k][l])%=MOD; g[k][l]=0; } } } REP(j,0,p3[m])(f[i+1][j]+=g[j][1])%=MOD; } int ans=0; REP(i,0,p3[m])if(__builtin_ctz(getpos0[i]|(1<<m))==m)(ans+=f[n][i])%=MOD; cout<<ans<<endl; } void TC() { REP(i,0,p3[9]){ int x=i; REP(j,0,9){ if(x%3==1)getpos1[i]|=1<<j; else if(x%3==0)getpos0[i]|=1<<j; x/=3; } } int tc=1; cin>>tc; while(tc--){ Main(); cout.flush(); } } signed main() { freopen("ov.in","r",stdin); freopen("ov.out","w",stdout); return cin.tie(0),cout.tie(0),ios::sync_with_stdio(0),TC(),0; } /* 1. CLEAR the arrays (ESPECIALLY multitests) 2. DELETE useless output */
- 1
Information
- ID
- 3104
- Time
- 2000ms
- Memory
- 512MiB
- Difficulty
- 10
- Tags
- (None)
- # Submissions
- 1
- Accepted
- 1
- Uploaded By