传送门

仔细观察可以发现,如果在一个\(> 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. pandas 读取excel文件对数据简单清洗并用matplotlib 将数据展示

    首先我们看下数据 接下来数据分析操作 import numpy as np import pandas as pd from matplotlib import pyplot as plt if __ ...

  2. python 当前时间获取方法

    1.先导入库:import datetime 2.获取当前日期和时间:now_time = datetime.datetime.now() 3.格式化成我们想要的日期:strftime() 比如:“2 ...

  3. Remote debugger is in a background tab which may cause apps to perform slowly. Fix this by foregrounding the tab (or opening it in a separate window).

    先上代码: /** * Sample React Native App * https://github.com/facebook/react-native * * @format * @flow * ...

  4. Maven初窥门径

    Maven项目对象模型,可以使用一小段描述来管理项目的构建,报告和文档的软件项目管理工具. 安装 下载地址:http://maven.apache.org/download.cgi 下载解压,我将它放 ...

  5. QSS网址

    http://blog.csdn.net/liang19890820/article/details/51691212 https://www.cnblogs.com/cy568searchx/p/3 ...

  6. Laravel 下生成验证码的类

    <?php namespace App\Tool\Validate; //验证码类 class ValidateCode { private $charset = 'abcdefghkmnprs ...

  7. 【CF280D】 k-Maximum Subsequence Sum ,线段树模拟费用流

    昨天考试被教育了一波.为了学习一下\(T3\)的科技,我就找到了这个远古时期的\(cf\)题(虽然最后\(T3\)还是不会写吧\(QAQ\)) 顾名思义,这个题目其实可以建成一个费用流的模型.我们用流 ...

  8. (map)What Are You Talking About hdu1075

    What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K ...

  9. 在linux下面解压用的zxpf是什么意思,它跟zxvf有啥区别

    在linux下面解压用的zxpf是什么意思,它跟zxvf有啥区别 linux 命令中tar后跟的zxvf是什么意思:.tar.gz是一个压缩包   .tar只是打包而没有压缩 z:表示 tar 包是被 ...

  10. hadoop 分布式开发环境搭建

    一,安装java环境 添加java环境变量 vi /etc/profile   # add by tank export JAVA_HOME=/data/soft/jdk/jdk1.7.0_71 ex ...