ARC071D Infinite Sequence
仔细观察可以发现,如果在一个\(> 1\)的数后面放一个\(> 1\)的数,那么后面的序列也就确定了,所以我们考虑dp出特定长度的序列,然后在后面加上能确定序列的数来贡献答案
为了凑出这样的序列,用来填充的东西是单个的\(1\),或者长度为\(x+1(x>1)\)的 \(x\)加\(x\)个\(1\),所以转移就是\(f_i=\sum_{j=0}^{i-1}[j\ne i-2]f_j\),注意不能加上\(f_{i-2}\),因为\(1\ 1\)会和\(1\)加\(1\)算重
然后考虑\(f_i\)的贡献,如果\(i<n-1\),首先可以加上\(xyyyy...(x>1,y>1)\),然后也可以加上\(x11111(x>1\)且\(i+x+1\ge n)\),因为凑到n时后面就全是\(1\)了;如果\(i=n-1\),那么n号位放什么,后面就是什么,所以可以放一个\([1,n]\)的数
渣渣灰代码警告
#include<bits/stdc++.h>
#define LL long long
#define db double
#define il inline
#define re register
#define mkpr make_pair
using namespace std;
const int N=1e6+10,mod=1e9+7;
il LL rd()
{
LL x=0,w=1;char ch=0;
while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
return x*w;
}
int n,m,f[N],ans;
int main()
{
n=rd();
m=(1ll*(n-1)*(n-1))%mod;
ans=m+1+(n>2); //整个序列可以是xyyyy,也可以是n11111或者(n-1)11111
int sm=f[0]=1;
for(int i=1;i<n;++i)
{
f[i]=sm;
if(i-2>=0) f[i]=(f[i]-f[i-2]+mod)%mod;
sm=(sm+f[i])%mod;
if(i!=n-1) ans=(ans+1ll*f[i]*(m+min(i+2,n-1))%mod)%mod; //乘的东西代表的分别是xyyyy和x1111
else ans=(ans+1ll*f[i]*n%mod)%mod;
}
printf("%d\n",ans);
return 0;
}
ARC071D Infinite Sequence的更多相关文章
- CodeForces 622 A.Infinite Sequence
A.Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 7 A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...
- codeforces 675A A. Infinite Sequence(水题)
题目链接: A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input st ...
- codeforces 622A Infinite Sequence
A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 【arc071f】Infinite Sequence(动态规划)
[arc071f]Infinite Sequence(动态规划) 题面 atcoder 洛谷 题解 不难发现如果两个不为\(1\)的数连在一起,那么后面所有数都必须相等. 设\(f[i]\)表示\([ ...
- Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...
- codeforces 622A A. Infinite Sequence (二分)
A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...
- A - Infinite Sequence
Problem description Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, ...
- Codeforces Round #353 (Div. 2) A. Infinite Sequence
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its fi ...
随机推荐
- Up-to-date cache with EclipseLink and Oracle
Up-to-date cache with EclipseLink and Oracle One of the most useful feature provided by ORM librarie ...
- java ee wildfly 批处理 job 工作
配置批处理job,同时启动两个并行任务processData,syncTableTask,执行往后执行第三个任务job:playDurationTask. xml配置如下: <job id=&q ...
- 【洛谷P3455】ZAP-Queries
题目大意:求 \[\sum\limits_{i=1}^a\sum\limits_{j=1}^b[gcd(i,j)=c]\] 题解:学会了狄利克雷卷积. \[\epsilon=\mu \ast 1\] ...
- 快速傅里叶变换(FFT)
扯 去北京学习的时候才系统的学习了一下卷积,当时整理了这个笔记的大部分.后来就一直放着忘了写完.直到今天都腊月二十八了,才想起来还有个FFT的笔记没整完呢.整理完这个我就假装今年的任务全都over了吧 ...
- python字符串的常用方法
- Ubuntu17安装Chrome有效
http://blog.csdn.net/NFMSR/article/details/78348000 1.进入 Ubuntu 16.04 桌面,按下 Ctrl + Alt + t 键盘组合键,启动终 ...
- HDU 1560 DNA sequence (迭代加深搜索)
The twenty-first century is a biology-technology developing century. We know that a gene is made of ...
- 基于LVM卷的MYSQL快照恢复
在mysql数据库环境中,如果数据库数据很重要,可以使用LVM卷管理的方式,通过对数据卷进行快照,得到快速备份的目的, 首先回顾一下LVM卷管理的几个概念: 物理磁盘PD,physical disk, ...
- BSGS与exBSGS学习笔记
\(BSGS\)用于解决这样一类问题: 求解\(A^x ≡B(modP)\)的最小\(x\),其中\(P\)为质数. 这里我们采用分块的方法,把\(x\)分解为\(i *t-b\)(其中\(t\)是分 ...
- python数据结构总结
一.列表 1.列表脚本操作符: (1)扩增的操作符: “+”:用于组合列表:如[1,2,3]+[4,5,6]==>[1,2,3,4,5,6] "*":重复;如[2,3]*2= ...