#include<cstring>
#include <cstdio>
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn = (1<<16)+11;
const int N = 20;
LL val[N],d[maxn];
int n;
bool vis[maxn];
LL dp(int s,int num){
if(vis[s]) return d[s];
vis[s]=true;
if(s==(1<<n)-1) return d[s]=1;
d[s]=0;
for(int i=0;i<n;i++) if(!((s>>i)&1) && ((num>>i)&1)){
d[s]+=dp(s|(1<<i),num|val[i]);
}
return d[s];
}
char str[maxn];
int main(){
int T,kase=1;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
int weapon;
for(int i=0;i<=n;i++){
scanf("%s",str);
int num=0;
for(int j=n-1;j>=0;j--){
num=num*2+str[j]-'0';
}
if(!i) weapon=num;
else val[i-1]=num;
}
memset(vis,false,sizeof(vis));
printf("Case %d: %lld\n",kase++,dp(0,weapon));
}
return 0;
}
UVA -(11795 weapon 状态的附加信息不需再开一维)
最新推荐文章于 2016-05-31 14:54:48 发布