我,ycl:BM是什么早就忘了!

毕老爷:那你们可以做一做这道题练练BM板子啊。

传送门

 //Achen
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Rep(i,a,b) for(int i=(a);i>=(b);i--)
#define Formylove return 0
const int N=1e5+,p=1e9+;
typedef long long LL;
typedef double db;
using namespace std;
int n,m;
LL f[][]; template<typename T> void read(T &x) {
char ch=getchar(); T f=; x=;
while(ch!='-'&&(ch<''||ch>'')) ch=getchar();
if(ch=='-') f=-,ch=getchar();
for(;ch>=''&&ch<='';ch=getchar()) x=x*+ch-''; x*=f;
} int main() {
freopen("1.in","r",stdin);
//freopen("biao.in","w",stdout);
read(m); read(n);
For(i,,m) f[][i]=;
For(i,,n) {
if(i>) For(j,,m) f[i][j]=f[i-][m-j];
For(j,,m) f[i][j]=(f[i][j]+f[i][j-])%p;
}
printf("%lld\n",f[][m]);
//printf("%d\n",n);
//For(i,1,n) printf("%lld ",f[i][m]);
//printf("%lld\n",f[n][m]);
Formylove;
}

n^2暴力

//Achen
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<queue>
#include<cmath>
#include<set>
#include<map>
#define Formylove return 0
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Rep(i,a,b) for(int i=(a);i>=(b);i--)
const int N=,p=1e9+;
typedef long long LL;
typedef double db;
using namespace std;
int n,cnt,fail[N];
vector<LL>f[N];
LL a[N],delta[N]; template<typename T>void read(T &x) {
char ch=getchar(); x=; T f=;
while(ch!='-'&&(ch<''||ch>'')) ch=getchar();
if(ch=='-') f=-,ch=getchar();
for(;ch>=''&&ch<='';ch=getchar()) x=x*+ch-''; x*=f;
} LL ksm(LL a,LL b) {
LL rs=,bs=a%p;
while(b) {
if(b&) rs=rs*bs%p;
bs=bs*bs%p;
b>>=;
}
return rs;
} #define ANS
int main() {
#ifdef ANS
freopen("biao.in","r",stdin);
freopen("shizi.out","w",stdout);
#endif
read(n);
For(i,,n) read(a[i]);
For(i,,n) {
LL tp=; int up=f[cnt].size();
For(j,,up-) tp=(tp+f[cnt][j]*a[i-j-]%p)%p;
if(tp==a[i]) continue;
delta[i]=(a[i]-tp+p)%p;
fail[cnt]=i;
++cnt;
if(cnt==) {
f[cnt].resize(i);
continue;
}
LL mul=delta[i]*ksm(delta[fail[cnt-]],p-)%p,fmul=(p-mul)%p;
f[cnt].resize(i-fail[cnt-]-);
f[cnt].push_back(mul);
up=f[cnt-].size();
For(j,,up-) f[cnt].push_back(fmul*f[cnt-][j]%p);
up=f[cnt-].size();
if(f[cnt].size()<f[cnt-].size()) f[cnt].resize(up);
For(j,,up-) f[cnt][j]=(f[cnt][j]+f[cnt-][j])%p;
}
int up=f[cnt].size();
printf("%d\n",up);
For(i,,up-) printf("%lld ",f[cnt][i]);
Formylove;
}

BM出递推

 //Achen
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Rep(i,a,b) for(int i=(a);i>=(b);i--)
#define Formylove return 0
const int N=1e5+,p=1e9+;
typedef long long LL;
typedef double db;
using namespace std;
int cnt;
LL A[N],f[N],n; template<typename T> void read(T &x) {
char ch=getchar(); T f=; x=;
while(ch!='-'&&(ch<''||ch>'')) ch=getchar();
if(ch=='-') f=-,ch=getchar();
for(;ch>=''&&ch<='';ch=getchar()) x=x*+ch-''; x*=f;
} LL rs[N],bs[N],tp[N];
void cheng(LL a[],LL b[]) {
For(i,,cnt*) tp[i]=;
For(i,,cnt-) For(j,,cnt-)
(tp[i+j]+=a[i]*b[j])%=p;
Rep(i,cnt*-,cnt) if(tp[i])
For(j,,cnt-)
(tp[i-j-]+=A[j]*tp[i]%p)%=p;
For(i,,cnt-) a[i]=tp[i];
} void ksm(LL b) {
while(b) {
if(b&) cheng(rs,bs);
cheng(bs,bs);
b>>=;
}
} int main() {
freopen("shizi.out","r",stdin);
//freopen("shizi.out","w",stdout);
read(cnt);
For(i,,cnt-) read(A[i]);
read(n);
rs[]=; bs[]=; ksm(n-);
For(i,,cnt) read(f[i]);
LL ans=;
For(i,,cnt-) ans=(ans+f[i+]*rs[i]%p)%p;
printf("%lld\n",ans);
Formylove;
}

多项式取模

ProjectEuler654的更多相关文章

随机推荐

  1. 字典,字符串,元组,字典,集合set,类的初步认识,深浅拷贝

    Python之路[第二篇]:Python基础(一)   入门知识拾遗 一.作用域 对于变量的作用域,执行声明并在内存中存在,该变量就可以在下面的代码中使用. if 1==1: name = 'Jaso ...

  2. php基础知识测试总结

    1.LAMP具体结构包括Linux系统,Apache服务器,MySQL数据库,PHP语言. WAMP具体结构包括Windows系统,Apache服务器,MySQL数据库,PHP语言. 2.B/S架构: ...

  3. xml转换为对象 微信接口

    public sealed class XMLSerilizable { /// <summary> /// XML转换为对象 /// </summary> /// <t ...

  4. linux基础三---网络基础&软件包管理

    一 ifconfig:显示所有正在启动的网卡的详细信息或设定系统中网卡的IP地址. ifconfig eno16777736 down/up   关闭/开启 eno16777736 网卡 ifconf ...

  5. verilog中一些基本的门电路如pmos和nmos等

    最近在分析波形的时候,发现某个PAD模型的行为与想象的不一致,就进入stdcell里面看了下,主要是pmos和nmos相关的东西,暂列如下: 开关级基元14种 是实际的MOS关的抽象表示,分电阻型(前 ...

  6. PreTranslateMessage作用和使用方法

    PreTranslateMessage作用和使用方法  PreTranslateMessage是消息在送给TranslateMessage函数之前被调用的,绝大多数本窗口的消息都要通过这里,比较常用, ...

  7. SpringBoot 通用Validator

    第一步,pom.xml引入hibernate-validator <dependency> <groupId>org.hibernate</groupId> < ...

  8. .NET及JAVA 中如何使用代码启动程序

    .NET 中: System.Diagnostics.Process.Start("应用程序");    JAVA中: ProcessBuilder pb=new ProcessB ...

  9. mysql服务器3306端口不能远程连接的解决

    1.网络检测   1)ping主机可以:   2)telnet 主机3306端口不可以:     telnet 主机22端口可以:   说明与本机网络没有关系: 2.端口检测   1)netstat ...

  10. Linux学习笔记001——win下安装Linux虚拟机

    我研二之前算是一个纯粹的计算机小白,因为某些原因开始接触了计算机方面的知识. Linux系统也就是前几个月才听说,因某些需求需要在Linux环境下运行.纯的Linux系统不太现实, 所以在他人帮助和自 ...