大意:定义一个长为$k>1$且首项为$k-1$的区间为好区间. 定义一个能划分为若干个好区间的序列为好序列. 给定序列$a$, 求有多少个子序列为好序列.

刚开始一直没想出来怎么避免重复计数, 看了别人题解才会.

设$dp[i]$为以$a_i$开头的个数, 枚举$a_i$所在好区间的最后一个数$j$, 有$dp[i]=\sum \binom{j-1-1}{a_i-1}\sum\limits_{k=j+1}^n dp[k]$

#include <iostream>
#include <algorithm>
#include <cstdio>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
using namespace std;
typedef long long ll;
const int P = 998244353, INF = 0x3f3f3f3f;
const int N = 1e3+10;
int n,a[N],dp[N],C[N][N],sum[N]; int main() {
scanf("%d", &n);
REP(i,1,n) scanf("%d", a+i);
REP(i,0,n) {
C[i][0] = 1;
REP(j,1,i) C[i][j]=(C[i-1][j]+C[i-1][j-1])%P;
}
int ans = 0;
PER(i,1,n) {
if (a[i]>0) {
REP(j,i+a[i],n) dp[i] = (dp[i]+C[j-i-1][a[i]-1]*(1ll+sum[j+1]))%P;
}
sum[i] = (sum[i+1]+dp[i])%P;
}
printf("%d\n",sum[1]);
}

Yet Another Problem On a Subsequence CodeForces - 1000D (组合计数)的更多相关文章

  1. D - Yet Another Problem On a Subsequence CodeForces - 1000D (DP,组合数学)

    D - Yet Another Problem On a Subsequence CodeForces - 1000D The sequence of integers a1,a2,-,aka1,a2 ...

  2. Anton and School - 2 CodeForces - 785D (组合计数,括号匹配)

    大意: 给定括号字符串, 求多少个子序列是RSGS. RSGS定义如下: It is not empty (that is n ≠ 0). The length of the sequence is ...

  3. Different Subsets For All Tuples CodeForces - 660E (组合计数)

    大意: 定义$f(a)$表示序列$a$本质不同子序列个数. 给定$n,m$, 求所有长$n$元素范围$[1,m]$的序列的$f$值之和. 显然长度相同的子序列贡献是相同的. 不考虑空串, 假设长$x$ ...

  4. Singer House CodeForces - 830D (组合计数,dp)

    大意: 一个$k$层完全二叉树, 每个节点向它祖先连边, 就得到一个$k$房子, 求$k$房子的所有简单路径数. $DP$好题. 首先设$dp_{i,j}$表示$i$房子, 分出$j$条简单路径的方案 ...

  5. Intercity Travelling CodeForces - 1009E (组合计数)

    大意: 有一段$n$千米的路, 每一次走$1$千米, 每走完一次可以休息一次, 每连续走$x$次, 消耗$a[1]+...+a[x]$的能量. 休息随机, 求消耗能量的期望$\times 2^{n-1 ...

  6. GukiZ and Binary Operations CodeForces - 551D (组合计数)

    大意: 给定$n,k,l,m$, 求有多少个长度为$n$, 元素全部严格小于$2^l$, 且满足 的序列. 刚开始想着暴力枚举当前or和上一个数二进制中$1$的分布, 但这样状态数是$O(64^3)$ ...

  7. Max History CodeForces - 938E (组合计数)

    You are given an array a of length n. We define fa the following way: Initially fa = 0, M = 1; for e ...

  8. Consecutive Subsequence CodeForces - 977F(dp)

    Consecutive Subsequence CodeForces - 977F 题目大意:输出一序列中的最大的连续数列的长度和与其对应的下标(连续是指 7 8 9这样的数列) 解题思路: 状态:把 ...

  9. D. Yet Another Problem On a Subsequence 解析(DP)

    Codeforce 1000 D. Yet Another Problem On a Subsequence 解析(DP) 今天我們來看看CF1000D 題目連結 題目 略,請直接看原題 前言 這題提 ...

随机推荐

  1. Go By Example-值类型

    Go By Example-值类型 Go语言的数据类型可以分为值类型和引用类型,这里先说值类型. 值类型 值类型:在Go语言中int.float.bool和string这些类型都属于值类型,使用这些类 ...

  2. 2018-2019-2 网络对抗技术 20165311 Exp 9 Web安全基础

    2018-2019-2 网络对抗技术 20165311 Exp 9 Web安全基础 基础问题回答 实践过程记录 WebGoat安装 SQL注入攻击 1.命令注入(Command Injection) ...

  3. arcgis python 开启编辑会话和编辑操作、在表中创建行、停止编辑操作以及提交编辑会话。

    import arcpy import os fc = 'Database Connections/Portland.sde/portland.jgp.schools' workspace = os. ...

  4. What is the difference between XSS and CSRF from their execution perspective?

    What is the difference between XSS and CSRF from their execution perspective? https://www.quora.com/ ...

  5. matlab图像灰度调整——imadjust函数的使用

    在MATLAB中,通过函数imadjust()进行图像灰度的调整,该函数调用格式如下: J=imadjust( I )  对图像I进行灰度调整 J=imadjust( I,[low_in;high_i ...

  6. Block pool ID needed, but service not yet registered with NN java.lang.Exception: trace 异常解决

    以上为报错信息: 原因大概为:dd和nd关联的versionId不同导致, 解决方案,备份之前的current文件夹,让其自己生成新的.

  7. 通用的调用WebService的两种方法。(调用别人提供的wsdl)(转)

    转载自:http://blog.sina.com.cn/s/blog_65933e020101incz.html1.调用WebService的Client端采用jax-ws调用WebService:流 ...

  8. delphi字符串分隔函数用法实例

    这篇文章主要介绍了delphi字符串分隔函数用法,通过自定义函数SeparateTerms2实现将字符串分割后存入字符串列表的功能,具有一定的实用价值,需要的朋友可以参考下 本文实例讲述了delphi ...

  9. Delphi中动态加载TreeView信息

    unit Unit3; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  10. sqlserver如何创建链接服务器

    遇到下列问题: 线上服务器A,中转服务器B,本地服务器C 数据在A上面,想在B上面操作类似 select * from [A].[database].table这样的SQL,不用去链接服务器,直接把处 ...