传送门

题目大意

给定一个数$n$,构造一个无限长的序列$A$,使得

$\forall i,j\geq n,A_i=A_j$

$\forall i<j<k\leq i+a_i,A_j=A_k$

求构造总方案数,$n\leq 10^6$,答案对$10^9+7$取模。

题解

易证对于$i<n$若$\exists A_i>1,A_{i+1}>1$,那么一定$\forall j>i+1,a_j=a_i$。

设$DP$状态$F_i$表示第$a_i=1$且$\forall j<i,j+A_j\leq i$的方案数。

考虑第$i$位作为一个$j<i,A_j+j=i,A_j>1$的结尾,那么有$F_i+=\sum\limits_{j=0}^{i-3}F_j$

否则$F_i+=F_{i-1}$。

枚举结尾是$A_n,A_{n-1}>1$或$\exists A_j>1,A_n=1,A_j+j>n$或$\max\{A_j+j\}\leq n$。

对于第一种情况,直接枚举最后一个$1$出现的位置$i$对答案的贡献为$F_i\times (n-1)^2$

对于第二种情况,枚举$j$出现的位置(显然只会出现一个),一定有$A_{j-1}=1$,对答案的贡献为$F_{j-1}\times (j-[j<n])$,因为要满足$j+A_j+1>n,A_j>1$。

对于第三种情况,对答案的贡献直接就是$F_n$。

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 2000200
#define mod 1000000007
using namespace std;
namespace IO{
int Top=0;char SS[20];
void write(int x){
if(!x){putchar('0');return;} if(x<0) x=-x,putchar('-');
while(x) SS[++Top]=x%10,x/=10;
while(Top) putchar(SS[Top]+'0'),--Top;
}
int read(){
int nm=0; char cw=getchar(); for(;!isdigit(cw);cw=getchar());
for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0'); return nm;
}
}using namespace IO;
int add(int x,int y){return (x+y>=mod)?x+y-mod:x+y;}
int mul(int x,int y){return (LL)x*(LL)y%mod;}
void upd(int &x,int y){x=add(x,y);}
int n,m,F[M],S[M],ans;
int main(){
n=read(),F[0]=S[0]=1;
for(int i=1;i<=n;i++) F[i]=i>2?S[i-3]:0,upd(F[i],F[i-1]),S[i]=add(S[i-1],F[i]);
for(int i=0;i<n;i++) upd(ans,mul(F[i],i+(i<n-1)));
for(int i=0;i<n-1;i++) upd(ans,mul(F[i],mul(n-1,n-1)));
upd(ans,F[n]),write(ans),putchar('\n');return 0;
}

Arc071_F 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. ios 手势返回<1>

    极其简单取巧的方法 iOS7之后是有侧滑返回手势功能的.注意,也就是说系统已经定义了一种手势,并且给这个手势已经添加了一个触发方法(重点).但是,系统的这个手势的触发条件是必须从屏幕左边缘开始滑动.我 ...

  2. 【BZOJ3112】[Zjoi2013]防守战线 单纯形法

    [BZOJ3112][Zjoi2013]防守战线 题解:依旧是转化成对偶问题,然后敲板子就行了~ 建完表后发现跟志愿者招募的表正好是相反的,感觉很神奇~ #include <cstdio> ...

  3. 【BZOJ1513】[POI2006]Tet-Tetris 3D 二维线段树

    [BZOJ1513][POI2006]Tet-Tetris 3D Description Task: Tetris 3D "Tetris" 游戏的作者决定做一个新的游戏, 一个三维 ...

  4. Python学习笔记(二)在线用pip下载第三方包

    根据他人的博客,可以发现pip也是可以离线安装已经下载好的包的,具体请参考<pip常用命令>.由于现在还没进展到那个程度,所以本次博客先记录一下我已经学会的东西. 1.pip基本用法 (1 ...

  5. 如何将gedit变成c++编译器

    本蒟蒻的第一篇文章,分享一下神佬教我的好东西 ——将Ubuntu 16.04上gedit变为编译器! 1° 新建文档.然后点击编辑,打开首选项. 2° 勾选外部工具,然后退出.打开工具,选择Manag ...

  6. The given 'driver' ] is unknown, Doctrine currently supports only the follo wing drivers: pdo_mysql, pdo_sqlite, pdo_pgsql, pdo_oci, oci8, ibm_db2, pdo

    [Doctrine\DBAL\DBALException]                                                  The given 'driver' ] ...

  7. c++得到本地username和IP

    bool CDlgResetAlarmInfo::GetLocalUserNameAddIP(CString &a_lstrUserName ,CString &a_IpStr) { ...

  8. vue页面性能优化方案

    个人在项目中用到的页面性能优化的方式总结. 一.均衡页面加载文件的大小和数量 1.项目中小图片图片转base64,通过工具如webpack进行图片压缩,文件进行压缩混淆等 2.vue-router 懒 ...

  9. Java多线程系列 JUC线程池02 线程池原理解析(一)

    转载  http://www.cnblogs.com/skywang12345/p/3509960.html ; http://www.cnblogs.com/skywang12345/p/35099 ...

  10. sqlserver 2008 创建数据库的时候不是空库,里面总有数据的解决办法

    SqlServer2008 里面有个系统数据库 Model 数据库,在创建新数据库的时候,会以它为模板创建,所以如果发现你的Model数据库比较大,说明里面有很多模板数据.此时如果需要去创建没有数据的 ...