我,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. Ajax+Spring MVC实现跨域请求(JSONP)

    背景: AJAX向后台(springmvc)发送请求,报错:已阻止交叉源请求:同源策略不允许读取 http://127.0.0.1:8080/DevInfoWeb/getJsonp 上的远程资源.可 ...

  2. 安装MySQL的详细步骤

    安装步骤如下: 1.打开网址:http://www.mysql.com/ ↓ 2.选择“Download”->“Windows”(此安装步骤只是在Window10 中进行,如有需要,其他系统可参 ...

  3. ArchiMate进行业务架构建模的参考

    业务服务视图 业务渠道视图 业务服务实现视图 业务角色协作视图 业务流程协作视图 业务流程视图 业务对象视图 产品化业务服务视图 分层视图 除了以上内容,在TOGAF中完整的推荐视图是 在ArchiM ...

  4. jquery图片过滤归类应用

    在线演示 本地下载

  5. codeforces 155D 质数

    题意:有编号1到n的n台机器,有m次操作,操作为开启或关闭机器,成功开启机器k的条件为k和所有已经开启的机器编号互质. 思路:vis[i]数组存放占领i这个位置的机器编号,因为所有开启的机器的编号互质 ...

  6. 如何判断Linux服务器是否被入侵?

    被入侵服务器的症状 当服务器被没有经验攻击者或者自动攻击程序入侵了的话,他们往往会消耗 100% 的资源.他们可能消耗 CPU 资源来进行数字货币的采矿或者发送垃圾邮件,也可能消耗带宽来发动 DoS ...

  7. 用javascript实现的验证码

    <html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">     ...

  8. javascript 内置对象及常见API

    javascript 内置对象及常见API 2012-09-02 15:17 571人阅读 评论(0) 收藏 举报 javascript正则表达式文档浏览器urlstring Javascript内置 ...

  9. POJ 3167 Cow Patterns (KMP+前缀和)

    题意:给你两串数字,长度分别为n和m,数字大小在[1,25].当后一串数字每个数字的排名位置与前一串数字(任一长度为m的子串)每个数字的排名位置一致时就完全匹配,最后求哪些位置是完全匹配的. 例如:1 ...

  10. python 之CORS,VUE+rest_framework示例

    一.跨域     浏览器的同源策略                 ----对ajax请求进行阻拦                 ----对href属性读不阻拦        xhr=new XML ...