【arc071f】Infinite Sequence(动态规划)
【arc071f】Infinite Sequence(动态规划)
题面
题解
不难发现如果两个不为\(1\)的数连在一起,那么后面所有数都必须相等。
设\(f[i]\)表示\([i,n]\)的填法数,初值\(f[n]=n,f[n-1]=n*n\)
考虑转移,
首先可以这里填上一个大于\(1\)的数然后后面连续若干个\(1\),这一部分的方案数是\(\sum_{j=i+3}^n f[j]\),这个后缀和记录一下就好了,然而还漏了一部分,即如果\(i+a_i>n\),那么这里的贡献的方案数就是\(1\),所以还需要补上\(i+1\)。
第二种是在这一位填上连续两个大于\(1\)的数,方案数为\((n-1)^2\)。
第三种是在这一位填上一个\(1\),方案数是\(f[i+1]\)。
#include<cstdio>
#define MOD 1000000007
int n,f[1000010];
int main()
{
scanf("%d",&n);f[n]=n;f[n-1]=1ll*n*n%MOD;
for(int i=n-2,s=0;i>0;--i)s=(s+f[i+3])%MOD,f[i]=(f[i+1]+1ll*(n-1)*(n-1)+s+i+1)%MOD;
printf("%d\n",f[1]);return 0;
}
【arc071f】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 ...
- 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 ...
- UVa 1626 Brackets sequence (动态规划)
题意:用最少的括号将给定的字符串匹配,输出最优解.可能有空行. 思路:dp. dp[i][j]表示将区间i,j之间的字符串匹配需要的最少括号数,那么 如果区间左边是(或[,表示可以和右边的字符串匹配, ...
随机推荐
- eclipse如何添加web dynamic project
很多eclipse版本是不能直接新建web dynamic project的,需要从网上找插件或更新. 比较方便的是在Help → Install-New-Software,点击add按钮,在Loca ...
- Python之参数类型、变量
一.参数类型 (一)形参与实参 要使用局部变量时,只能通过return的方式返回 def my(name): #函数体 return name my('lrx') #name是形参,lrx是实参 不写 ...
- 企业级分布式应用服务EDAS _Dubbo商业版_微服务PaaS平台 【EDAS Serverless 运维 创业】
企业级分布式应用服务EDAS _Dubbo商业版_微服务PaaS平台_分布式框架 - 阿里云https://www.aliyun.com/product/edas?source_type=yqzb_e ...
- MySQL索引的设计、使用和优化
原文:http://bbs.landingbj.com/t-0-243071-1.html MySQL索引概述 所有MySQL列类型可以被索引.对相关列使用索引是提高SELECT操作性能的最佳途径.根 ...
- [转帖]buffer与cache的区别
作者:沈万马链接:https://www.zhihu.com/question/26190832/answer/146259979来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注 ...
- Angular 基本指令
<!DOCTYPE html><html ng-app><head lang="en"> <meta charset="UTF- ...
- C# Note12:WPF只允许数字的限制性TextBox
在使用中,我们经常遇到文本框中只允许输入数字(整型数或浮点数...) 的情况,如果我们输入特殊字符(字母和符号...),在获取其输入值时,如果先做判断或其他处理,会直接导致application发生c ...
- cmd & tree & bash
cmd & tree & bash bug E: Unable to locate package tree solution # 1. update $ sudo apt-get u ...
- 关于浏览器兼容问题——还有移动端meta问题
<!DOCTYPE html><!--[if lt IE 7]> <html dir="ltr" lang="en-US" cla ...
- 莫烦theano学习自修第七天【回归结果可视化】
1.代码实现 from __future__ import print_function import theano import theano.tensor as T import numpy as ...