博客
关于我
2016vijos 1-3 兔子的晚会(生成函数+倍增FWT)
阅读量:798 次
发布时间:2023-04-16

本文共 1683 字,大约阅读时间需要 5 分钟。

求出序列的生成函数后,倍增FWT

在解决某些序列问题时,我们需要求出序列的生成函数,并对其进行倍增快速傅里叶变换(FWT)。以下是实现这一过程的详细方法。

首先,我们在代码中定义了常量和模数:

#define N 2048const int mod=1e9+7;int inv;int f[N+1];

接下来,定义了一个快速幂的函数来计算大数的幂取模:

int Pow(int a,int b){    int res=1;    for(;b;a=1LL*a*a%mod,b >>=1)        if(b & 1) res = 1LL*res*a % mod;    return res;}

然后,实现了FWT变换和逆变换的函数。这些函数用于对序列进行快速傅里叶变换和逆变换:

void FWT(int *a,int n){    int x,y;    for(int d=1;d < n;d <<=1){        for(int m=d; m < n; m <<=1){            for(int i=0; i < n; i += m){                for(int j=0; j < d; j++){                    x = a[i+j];                    y = a[i+j+d];                    a[i+j] = (x + y) % mod;                    a[i+j+d] = (x - y + mod) % mod;                    a[i+j] -= a[i+j];                    a[i+j] %= mod;                    a[i+j+d] += a[i+j+d] < 0 ? mod : 0;                }            }        }    }}void IFWT(int *a,int n){    int x,y;    for(int d=1;d < n;d <<=1){        for(int m=d; m < n; m <<=1){            for(int i=0; i < n; i += m){                for(int j=0; j < d; j++){                    x = a[i+j];                    y = a[i+j+d];                    a[i+j] = (1LL*(x + y) * inv % mod);                    a[i+j+d] = (1LL*(x - y + mod) % mod * inv % mod);                }            }        }    }}

最后,在主函数中,我们读取输入并初始化变量:

int main(){    freopen("xor.in","r",stdin);    freopen("xor.out","w",stdout);    int n,m,l,r;    scanf("%d%d%d%d",&n,&m,&l,&r);    n = 2*n +1;    inv = Pow(2,mod-2);    len = 1;    ans = 0;    while(len <= x + m) len <<=1;    for(i=0; i < len; i++)        f[i] = Pow(f[i],n);    fwt(f,len);    ifwt(f,len);    ans += f[0];    printf("%d",ans);}

通过以上步骤,我们可以高效地求出序列的生成函数并对其进行倍增FWT变换,解决实际问题。

转载地址:http://fjgfk.baihongyu.com/

你可能感兴趣的文章
mysql:Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘解决方法
查看>>
MYSQL:基础——3N范式的表结构设计
查看>>
MYSQL:基础——触发器
查看>>
Mysql:连接报错“closing inbound before receiving peer‘s close_notify”
查看>>
mysqlbinlog报错unknown variable ‘default-character-set=utf8mb4‘
查看>>
mysqldump 参数--lock-tables浅析
查看>>
mysqldump 导出中文乱码
查看>>
mysqldump 导出数据库中每张表的前n条
查看>>
mysqldump: Got error: 1044: Access denied for user ‘xx’@’xx’ to database ‘xx’ when using LOCK TABLES
查看>>
Mysqldump参数大全(参数来源于mysql5.5.19源码)
查看>>
mysqldump备份时忽略某些表
查看>>
mysqldump实现数据备份及灾难恢复
查看>>
mysqldump数据库备份无法进行操作只能查询 --single-transaction
查看>>
mysqldump的一些用法
查看>>
mysqli
查看>>
MySQLIntegrityConstraintViolationException异常处理
查看>>
mysqlreport分析工具详解
查看>>
MySQLSyntaxErrorException: Unknown error 1146和SQLSyntaxErrorException: Unknown error 1146
查看>>
Mysql_Postgresql中_geometry数据操作_st_astext_GeomFromEWKT函数_在java中转换geometry的16进制数据---PostgreSQL工作笔记007
查看>>
mysql_real_connect 参数注意
查看>>