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的更多相关文章
随机推荐
- ruby rails 安裝
安装之前先更换Ubuntu的源 https://www.cnblogs.com/znsongshu/p/9452067.html http://gems.ruby-china.org/ 一/安 ...
- libhdfs的配置和使用
测试环境:centos6.10,hadoop2.7.3,jdk1.8 测试代码:HDFSCSample.c #include "hdfs.h" #include <strin ...
- Java智能图表类库JChartLib使用介绍
http://www.codeceo.com/article/java-jchartlib.html JChartLib是一款基于Java的智能图表类库,JChartLib不仅有着漂亮的外观,而且支持 ...
- 在看 jquery 源码中发现的一些优化方向
1. 避免使用 $.fn.each 或 $.each 因为它比原生的 for/while 真的会慢一些,循环次数越多差距越大. 另外,对象的 for-in 比 for 是要快一丢丢的,但数组的 for ...
- IMX6Q RTC驱动分析
对于在工作中学习驱动的,讲究的是先使用,再理解.好吧,我们来看看板子里是如何注册的? 在板文件里,它的注册函数是这样的: imx6q_add_imx_snvs_rtc() 好吧,让我们追踪下去: 1 ...
- Docker容器技术-优化Docker镜像
一.优化Docker镜像 1.降低部署时间 一个大的Docker应用是如何影响在新Docker宿主机上的部署时间. (1)编写Dockerfile创建一个大Docker镜像 [root@bogon ~ ...
- 快乐学习 Ionic Framework+PhoneGap 手册1-4 {登录页面}
编程的快乐和乐趣,来自于能成功运行程序并运用到项目中 有了面板然后加个登录页面,请看效果图和代码 Index HTML Code <!DOCTYPE html> <html ng-a ...
- 数据结构与算法分析:C语言描述(原书第2版 简体中文版!!!) PDF+源代码+习题答案
转自:http://www.linuxidc.com/Linux/2014-04/99735.htm 数据结构与算法分析:C语言描述(原书第2版中文版!!!) PDF+源代码+习题答案 数据结构与算法 ...
- iOS_KVC与KVO
目 录: 一.KVC 二.KVO ...
- java写出图形界面
1. 做出简单的窗体 package javaGUI; import java.awt.BorderLayout; import java.awt.Color; import javax.swing. ...