传送门

题目大意

给定一个数$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. jqury 如何获取 kindeditor 中textarea 的值

    获取文本内容,可是的创建时怎么也不能获取,利用FF的firebug查看到自己所写的内容在一个iframe中,于是想从iframe中获取文本,想要用 $(“ifame”).html();获取内容,可是依 ...

  2. PHP-Manual的学习----【语言参考】----【类型】-----【Resource 资源类型】

    2017年8月24日11:29:361.资源 resource 是一种特殊变量,保存了到外部资源的一个引用.资源是通过专门的函数来建立和使用的.2.由于资源类型变量保存有为打开文件.数据库连接.图形画 ...

  3. MFC添加菜单资源与菜单执行函数的两种命令形式

    添加资源->新建一个菜单资源->选择相应的对话框 菜单的执行函数命令形式: COMMAD 是指点击菜单后的执行命令 UPDATE_COMMAND_UI 是指点击菜单后菜单状态的函数

  4. (比赛)A - Simple String Problem

    A - Simple String Problem Time Limit:10000MS     Memory Limit:65536KB     64bit IO Format:%lld & ...

  5. windowsphone8.1学习笔记之Toast通知

    熟悉或者了解wp系统的人都知道wp的Toast,Toast(吐司)通知是在屏幕最顶上弹出来的提示框,它专为与锁屏提醒.磁贴通知和应用中UI结合使用而设计,但它不是MessageDialog.说简单点它 ...

  6. tomcat日志按天切分

    1. 下载工具cronolog wget http://cronolog.org/download/cronolog-1.6.2.tar.gz 这是网上流传的下载地址,好像没用,所以需要自己去网上找. ...

  7. CSS图片居中,多余隐藏

    /*外层DIV*/ div {position: relative;overflow:hidden;width: 显示宽度px;} /*left=50%刚好在中间,margin-left=往前移动图片 ...

  8. java实现数字的反转

    例如有一个数字是:19911002,要求是,我要得到它的反转后的数:20011991 实现如下: static void reverse(int a) { int rs = 0; while (a & ...

  9. Activiti使用过程_1

    1 微信公众号:

  10. NPM安装配置

    http://www.tuicool.com/articles/mmYZBn http://npm.taobao.org/ 安装Nodejs后即可开始NPM之旅了,新建一个package.json或者 ...