【arc071f】Infinite Sequence(动态规划)

题面

atcoder

洛谷

题解

不难发现如果两个不为\(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(动态规划)的更多相关文章

  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. Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题

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

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

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

  7. A - Infinite Sequence

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

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

  9. UVa 1626 Brackets sequence (动态规划)

    题意:用最少的括号将给定的字符串匹配,输出最优解.可能有空行. 思路:dp. dp[i][j]表示将区间i,j之间的字符串匹配需要的最少括号数,那么 如果区间左边是(或[,表示可以和右边的字符串匹配, ...

随机推荐

  1. Python_架构、同一台电脑上两个py文件通信、两台电脑如何通信、几十台电脑如何通信、更多电脑之间的通信、库、端口号

    1.架构 C/S架构(鼻祖) C:client  客户端 S:server  服务器 早期使用的一种架构,目前的各种app使用的就是这种架构,它的表现形式就是拥有专门的app. B/S架构(隶属于C/ ...

  2. Swagger UI 用法

    Swagger - 简书https://www.jianshu.com/p/4115f2b53983 Swagger简介 - Ghost Stories - CSDN博客https://blog.cs ...

  3. mysql 5.7:show_compatibility_56

    show_compatibility_56 - rudy gao - CSDN博客 https://blog.csdn.net/rudygao/article/details/50403107 [SO ...

  4. jmeter接口测试------基础笔记

    1.postman发送json格式的post请求,直接放链接 row里面body放请求参数,得到请求结果 2.jmeter请求json时需要注意在请求前创建http信息头管理器,然后信息头添加一条名称 ...

  5. python之路--初识面向对象

    一 . 初识面向对象 面向过程: 一切以事务的发展流程为中心. 面向对象: 一切以对象为中心. 一切皆为对象. 具体的某一个事务就是对象 打比方: 大象进冰箱 步骤: 第一步, 开门, 第二步, 装大 ...

  6. WPF中自定义MarkupExtension

    在介绍这一篇文章之前,我们首先来回顾一下WPF中的一些基础的概念,首先当然是XAML了,XAML全称是Extensible Application Markup Language (可扩展应用程序标记 ...

  7. ASP.NET4.0所有网页指令

    ASP.NET网页指令(Page Directive)就是在网页开头的标签声明: <% Page Language="C#" %> 而指令的作用在于指定网页和用户控件编 ...

  8. String 常见的十种方法!

    public class ZiFuChuan { public static void main(String[] args) { ZiFuChuanFangFa f=new ZiFuChuanFan ...

  9. shell命令相关

    1.服务端登录退出 登录服务器 ssh kayan.sjc@xx.xx.xx.67 退出登录:logout 192.168.0.10 2.目录管理 显示目录 pwd 创建目录 mkdir resour ...

  10. jqprint控件使用

    /*! jQuery v1.9.1 | (c) 2005, 2012 jQuery Foundation, Inc. | jquery.org/license //@ sourceMappingURL ...