51nod1773
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1773
#include<cstdio> #include<map> #define gc getchar() const int mod=1e9+7,inv2=(mod+1)>>1; int a[1<<21],b[1<<21]; int n,m; inline int fwt(int *a,int d,int f){ int x,y; for(register int i=1;i<d;i<<=1) for(register int j=0;j<d;j+=(i<<1)) for(register int k=j;k<i+j;++k){ x=a[k];y=a[i+k];a[k]=(x+y)%mod;a[i+k]=(x-y+mod)%mod; if(f==-1)a[k]=1ll*a[k]*inv2%mod,a[i+k]=1ll*a[i+k]*inv2%mod; } } inline int fp(int a,int b){ int res=1; while(b){ if(b&1)res=1ll*res*a%mod; a=1ll*a*a%mod;b>>=1; } return res; } inline int read(){ char c;while(c=gc,c==' '||c==' ');int data=c-48; while(c=gc,c>='0'&&c<='9')data=c-48+(data<<1)+(data<<3);return data; } int wr[51]; inline void write(int x){ if(!x){ puts("0"); return; } while(x)wr[++wr[0]]=x%10,x/=10; while(wr[0])putchar(48+wr[wr[0]--]); putchar(' '); } int main(){ n=read();m=read(); for(register int i=0;i<(1<<n);++i)a[i]=read(); b[0]=1;for(register int i=0;i<n;++i)b[1<<i]=1; fwt(a,(1<<n),1),fwt(b,(1<<n),1); for(register int i=0;i<(1<<n);++i)a[i]=1ll*a[i]*fp(b[i],m)%mod; fwt(a,(1<<n),-1); for(register int i=0;i<(1<<n);++i)write(a[i]); return 0; }
fwt板子
inline void FWT(int *a,int n){ for(register int d=1;d<n;d<<=1) for(register int m=d<<1,i=0;i<n;i+=m) for(register int j=0;j<d;++j){ int x=a[i+j],y=a[i+j+d]; //xor:a[i+j]=x+y,a[i+j+d]=x-y; //and:a[i+j]=x+y; //or:a[i+j+d]=x+y; } } inline void UFWT(int *a,int n){ for(register int d=1;d<n;d<<=1) for(register int m=d<<1,i=0;i<n;i+=m) for(register int j=0;j<d;++j){ int x=a[i+j],y=a[i+j+d]; //xor:a[i+j]=(x+y)/2,a[i+j+d]=(x-y)/2; //and:a[i+j]=x-y; //or:a[i+j+d]=y-x; } } inline void solve(int *a,int *b,int n){ FWT(a,n);FWT(b,n); for(register int i=0;i<n;++i) a[i]=1LL*a[i]*b[i]; UFWT(a,n); }