[CSU1911]Card Game
题目大意:
给定两个有n个数的数组\(A,B\),每次询问给定一个数,回答在每个数组里选一个数\(x\),或起来结果为\(x\)的方案数
FWT板子题,直接套就好(然后我居然把\(A_i\)++打成\(A_i\)=1了……)
/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline char gc(){
static char buf[1000000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int frd(){
int x=0,f=1; char ch=gc();
for (;ch<'0'||ch>'9';ch=gc()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=gc()) x=(x<<3)+(x<<1)+ch-'0';
return x*f;
}
inline int read(){
int x=0,f=1; char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+ch-'0';
return x*f;
}
inline void print(int x){
if (x<0) putchar('-'),x=-x;
if (x>9) print(x/10);
putchar(x%10+'0');
}
int mlt(int a,int b){
int res=1;
for (;b;b>>=1,a=a*a) if (b&1) res=res*a;
return res;
}
void FWT(ll *a,int n,int flag){
for (int i=2;i<=n;i<<=1)
for (int j=0;j<n;j+=i)
for (int k=0;k<i>>1;k++)
a[(i>>1)+j+k]+=a[j+k]*flag;
}
ll A[(1<<19)+10],B[(1<<19)+10],C[(1<<19)+10];
int n,m,Q;
int main(){
char s[30];
for (int T=read(),Case=0;T;T--){
printf("Case #%d:\n",++Case);
memset(A,0,sizeof(A));
memset(B,0,sizeof(B));
scanf("%d%d",&n,&m); m=1<<m;
for (int i=1;i<=n;i++){
scanf("%s",s);
int l=strlen(s),x=0;
for (int j=0;j<l;j++) x=(x<<1)+s[j]-'0';
A[x]++;
}
for (int i=1;i<=n;i++){
scanf("%s",s);
int l=strlen(s),x=0;
for (int j=0;j<l;j++) x=(x<<1)+s[j]-'0';
B[x]++;
}
FWT(A,m,1),FWT(B,m,1);
for (int i=0;i<m;i++) C[i]=A[i]*B[i];
FWT(C,m,-1);
scanf("%d",&Q);
for (int i=1;i<=Q;i++){
scanf("%s",s);
int l=strlen(s),x=0;
for (int j=0;j<l;j++) x=(x<<1)+s[j]-'0';
printf("%lld\n",C[x]);
}
}
return 0;
}