• 51nod1773 A国的贸易


    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);  
    }  
    

      

  • 相关阅读:
    utils:一个通用枚举类
    代码片段(二):SQL片段
    Scala:(一) 特点及安装环境配置
    Scala:(二) 语言基础-数据结构、表达式(判断、循环、块表达式)
    11-docker搭建mysql一主一从
    10-docker搭建rabbitmq集群
    尚硅谷周阳面试第二季
    docker 修改mysql 表大小写铭感
    volatile的理解
    消息队列优缺点及其选型
  • 原文地址:https://www.cnblogs.com/Stump/p/8456481.html
Copyright © 2020-2023  润新知