传送门

仔细观察可以发现,如果在一个\(> 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的更多相关文章

  1. CodeForces 622 A.Infinite Sequence

    A.Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. Educational Codeforces Round 7 A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...

  3. codeforces 675A A. Infinite Sequence(水题)

    题目链接: A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input st ...

  4. codeforces 622A Infinite Sequence

    A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. 【arc071f】Infinite Sequence(动态规划)

    [arc071f]Infinite Sequence(动态规划) 题面 atcoder 洛谷 题解 不难发现如果两个不为\(1\)的数连在一起,那么后面所有数都必须相等. 设\(f[i]\)表示\([ ...

  6. Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...

  7. codeforces 622A A. Infinite Sequence (二分)

    A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. A - Infinite Sequence

    Problem description Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2,  ...

  9. 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 ...

随机推荐

  1. 可以精准解析国内外网站的DNS

    Pure DNS https://puredns.cn/ XsicoDNS https://dns.xsico.cn/ Fun DNS http://www.fundns.cn/ Bai DNS ht ...

  2. bzoj4869: [Shoi2017]相逢是问候(欧拉函数+线段树)

    这题是六省联考的...据说数据还出了点锅,心疼六省选手QAQ 首先要知道扩展欧拉定理... 可以发现每次区间操作都会使模数进行一次phi操作,而一个数最多取logp次phi就会变成1,这时后面的指数就 ...

  3. 2050 Programming Competition (CCPC)

    Pro&Sol 链接: https://pan.baidu.com/s/17Tt3EPKEQivP2-3OHkYD2A 提取码: wbnu 复制这段内容后打开百度网盘手机App,操作更方便哦 ...

  4. 使用bedtools提取vcf多个位置的变异(extract multi-region of genotypes by bedtools)

    1.下载安装bedtools: 2.生成bed文件:标准的bed文件格式如下: chr7 127471196 127472363 Pos1 0 + 127471196 127472363 255,0, ...

  5. qml性能优化(来源于群友分享);

    Qt quick性能优化 使用时间驱动 避免定时轮询: 使用信号槽形式: 使用多线程 C++; QML WorkerScript元件: 使用Qt Quick Compiler 只需要再PRO文件中添加 ...

  6. 发送HTTP_GET请求 表头application/json

    /** * 发送HTTP_GET请求 * 该方法会自动关闭连接,释放资源 * @param reqURL 请求地址(含参数) * @param decodeCharset 解码字符集,解析响应数据时用 ...

  7. webpack打包进内联html

    用到一个新插件:html-webpack-inline-source-plugin(依赖于html-webpack-plugin) 1.安装 npm i -D html-webpack-inline- ...

  8. Burrow 服务的安装部署

    Burrow 服务的安装部署 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 最近协助开发的同时帮忙把10个topic的数据使用5个topic的来工作.结果发现数据flume在手机数 ...

  9. C++回顾day01---<命名空间>

    一:namespace是指标识符的各种控件范围(类java中package) C++语言引入命名空间(Namespace)这一概念主要是为了避免命名冲突,其关键字为 namespace 二:iostr ...

  10. Redis_集群_主从模式_哨兵模式

    1.主从模式 2.哨兵模式