ProjectEuler654
我,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的更多相关文章
随机推荐
- 每天一个Linux命令(57)rpm命令
rpm是一个功能十分强大的软件包管理系统. (1)用法: 用法: rpm [参数] [包名] (2)功能: 功能: 使得在Linux下安装.升级和删除软 ...
- 【leetcode刷题笔记】Word Ladder II
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...
- imx6qsbd lvds dtc
lvds显示屏调试参考 1.基于飞思卡尔imxsolosabresd开发板Linux-3.10.53 lvds屏幕调试: http://blog.csdn.net/qq_37375427/articl ...
- UVA11297 Census
题目 UVA11297 Census 做法 二维线段树,单点修改,矩阵查询,树套树(\(x,y\)),维护最大值最小值废话 有一点要注意的是:\(x\)树传到\(y\)树里面修改的时候,如果\(x\) ...
- PHP辅攻_[学习资料收集]PHP连接SQLServer2005方法
PHP连接SQLServer2005 1.修改php.ini将extension=php_mssql.dll的注释删除保存. 修改php.in将mssql.secure_connection = Of ...
- js原生插件格式解析
一个合格的插件必须满足以下要求: 1.拥有独立作用域与用户作用域隔离,插件内的私有变量不可影响用户定义的变量 2.拥有默认参数 3.提供配置方法让用户可改变参数 4.提供监听接口,以监听页面操作 5. ...
- 发现一个小坑的地方,unity的协程,想要停止,必须以字符串启动
今天想要停止一个协成,发现调用 StopCoroutine(ShowDebug()); 竟然不管用,后来看了文档才知道,原来想要停止协成,必须用字符启动协程 StartCoroutine(" ...
- 查找文件【TLCL】
locate locate 执行快速的路径名数据库搜索,输出每个与指定子字符串相匹配的路径名. locate bin/zip locate 命令的数据库是updatedb命令创建的. find loc ...
- Java基础(7)-集合类3
list集合的特点 1)有序(存储和取出的元素一直) 2)可重复 List子类的特点 ArrayList 有序,可重复 底层数据结构是数组 查询快,增删慢 线程不安全,效率高 Vector 有序,可重 ...
- 【转】Android BitmapShader 实战 实现圆形、圆角图片
转载自:http://blog.csdn.net/lmj623565791/article/details/41967509 1.概述 记得初学那会写过一篇博客Android 完美实现图片圆角和圆形( ...