博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 5730 Shell Necklace——多项式求逆+拆系数FFT
阅读量:4308 次
发布时间:2019-06-06

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

题目:

可以用分治FFT。但自己只写了多项式求逆。

和COGS2259几乎很像。设A(x),指数是长度,系数是方案。 \( A(x)^{k} \) 的 m 次项系数表示 k 个连续段组成长度为 m 的序列的方案数。

\( B(x)=1+F(x)+F^{2}(x)+F^{3}(x)+... \)

\( B(x) = \frac{1}{1-F(x)} \)(通过计算B(x)的逆来看出这个式子)

然后多项式求逆就行了。

注意模数 \( 313=2^{3}*3*13 \) ,原根是10,但那个 23 太小了!如果 len 大于3的话就会除出小数,所以不能直接用NTT!

那么就用FFT。FFT不能中途取模,所以最大的值是 312×312×10000=9734400000,会让FFT的精度变得很低。所以用拆系数FFT。

#include
#include
#include
#include
#include
#define db double#define ll long longusing namespace std;const int N=1e5+5,M=(1<<18)+5,mod=313;const db pi=acos(-1);int n,a[M],b[M],tp[M],len,r[M],base;struct cpl{db x,y;}A[M],B[M],Ta[M],Tb[M],Tc[M],Td[M],Ini,I;cpl operator+ (cpl a,cpl b){
return (cpl){a.x+b.x,a.y+b.y};}cpl operator- (cpl a,cpl b){
return (cpl){a.x-b.x,a.y-b.y};}cpl operator* (cpl a,cpl b){
return (cpl){a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x};}cpl cnj(cpl a){
return (cpl){a.x,-a.y};}int rdn(){ int ret=0;bool fx=1;char ch=getchar(); while(ch>'9'||ch<'0'){
if(ch=='-')fx=0;ch=getchar();} while(ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar(); return fx?ret:-ret;}void upd(int &x){x>=mod?x-=mod:0;}int pw(int x,int k){
int ret=1;while(k){
if(k&1)ret=(ll)ret*x%mod;x=(ll)x*x%mod;k>>=1;}return ret;}void fft(cpl *a,bool fx){ for(int i=1;i
>1; cpl wn=(cpl){ cos(pi/m),fx?-sin(pi/m):sin(pi/m) }; for(int i=0;i
>1]>>1)+((i&1)?len>>1:0); for(int i=0;i
>1,a,b); mtt(n,a,b,tp); mtt(n,tp,b,tp); for(int i=0;i
<<1)-tp[i])%mod+mod,upd(b[i]);}int main(){ base=sqrt(mod); I.x=1; while(1) { memset(a,0,sizeof a);memset(b,0,sizeof b); n=rdn(); if(!n)return 0; for(int i=1;i<=n;i++)a[i]=rdn(); for(int i=1;i<=n;i++)a[i]=mod-a[i]%mod,upd(a[i]); a[0]++; getinv(n+1,a,b); printf("%d\n",b[n]); } return 0;}

转载于:https://www.cnblogs.com/Narh/p/10056981.html

你可能感兴趣的文章
linux的基础知识
查看>>
接口技术原理
查看>>
五大串口的基本原理
查看>>
PCB设计技巧与注意事项
查看>>
linux进程之间通讯常用信号
查看>>
main函数带参数
查看>>
PCB布线技巧
查看>>
关于PCB设计中过孔能否打在焊盘上的两种观点
查看>>
PCB反推理念
查看>>
京东技术架构(一)构建亿级前端读服务
查看>>
php 解决json_encode中文UNICODE转码问题
查看>>
LNMP 安装 thinkcmf提示404not found
查看>>
PHP empty、isset、innull的区别
查看>>
apache+nginx 实现动静分离
查看>>
通过Navicat远程连接MySQL配置
查看>>
phpstorm开发工具的设置用法
查看>>
Linux 系统挂载数据盘
查看>>
Git基础(三)--常见错误及解决方案
查看>>
Git(四) - 分支管理
查看>>
PHP Curl发送数据
查看>>