跳到正文

剪贴板

剪贴板 d6p48ip4

原文
剪贴板信息

剪贴板信息

收录
更新
C++
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cassert>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <random>
#include <vector>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#define rep(i,j,k) for(int i=j;i<=(k);++i)
#define drp(i,j,k) for(int i=j;i>=(k);--i)
#define isdigit(ch) (ch>=48&&ch<=57)
#define mp std::make_pair
#define mod 998244353
#define MAXN 105
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef std::pair<int,int> pii;
const int dx[4]={1,-1,0,0};
const int dy[4]={0,0,1,-1};
const double eps=1e-6;
const double pi=acos(-1);
inline int read(){
	int x=0;
	char ch=getchar();
	bool f=false;
	while(!isdigit(ch)) f|=ch=='-',ch=getchar();
	while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return f?-x:x;
}
inline ll readll(){
	ll x=0;
	char ch=getchar();
	bool f=false;
	while(!isdigit(ch)) f|=ch=='-',ch=getchar();
	while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return f?-x:x;
}
template<typename tp> inline tp min(tp a,tp b){return a<b?a:b;}
template<typename tp> inline tp max(tp a,tp b){return a>b?a:b;}
template<typename tp> inline bool chkmin(tp &a,tp b){return a>b&&(a=b,true);}
template<typename tp> inline bool chkmax(tp &a,tp b){return a<b&&(a=b,true);}
int n,m,t[MAXN];
ll f[MAXN][1<<11];
int main(){
	freopen("travel.in","r",stdin);
	freopen("travel.out","w",stdout);
	drp(task,read(),1){
		n=read();
		rep(i,0,n) t[i]=read();
		while(t[0]>>m) ++m;
		rep(i,0,m) rep(s,0,(1<<n)-1) f[i][s]=0;
		f[0][1]=1;
		rep(i,0,m-1){
			int tot=n*((t[0]>>i)&1);
			rep(s,1,(1<<n)-1) if(f[i][s]){
				int sx=0,sy=0;
				rep(j,0,n) if((s>>j)&1) rep(k,0,tot) if(!k||((t[k]>>i)&1)){
					if((j+k)&1) sx^=1<<((j+k)>>1);
					else sy^=1<<((j+k)>>1);
				}
				f[i+1][sx]+=f[i][s];
				f[i+1][sy]+=f[i][s];
			}
		}
		ll ans=0;
		rep(s,0,(1<<n)-1) rep(j,0,n) if(s>>j&1) ans+=f[m][s];
		printf("%lld\n",ans);
	}
}