大意:定义一个长为$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. OPPO数据中台之基石:基于Flink SQL构建实数据仓库

    小结: 1. OPPO数据中台之基石:基于Flink SQL构建实数据仓库 https://mp.weixin.qq.com/s/JsoMgIW6bKEFDGvq_KI6hg 作者 | 张俊编辑 | ...

  2. es6对象复制合并 Object.assign

    对象的复制 var obj= { a: 1 }; var copy = Object.assign({}, obj); console.log(copy); //{ a: 1 } 对象的合并和封装 v ...

  3. Android:Recents和AMS中历史任务的区别

    1.1 任务和返回栈 - 实际数据模型  这个是指在调度体系里实际保存的TaskRecord实例,而ActivityRecord-TaskRecord-ActivityStack之间的关系建议看官方文 ...

  4. osgGA::KeySwitchMatrixManipulator 跟随

    #ifdef _WIN32 #include <Windows.h> #endif // _WIN32 #include <osg/Group> #include <os ...

  5. osg::NodeVisitor example

    [0]osg::Group [1]osg::MatrixTransform [1] osg::MatrixTransform [1]osg::MatrixTransform [2] osg::Geod ...

  6. osg qt 三维模型加载

    osg::ref_ptr<osg::Node> OSG_Qt_::operateMatrix() { osg::ref_ptr<osg::Group> group = new ...

  7. laravel中redis pipeline用法说明

    $res = Redis::pipeline(function($pipe) use($params) { for ($i = 0; $i < 1000; $i++) { $pipe->g ...

  8. css3 animation 点亮灯光效果

    <style> .wrap .bulb { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50% ...

  9. page工具类

    工具类 /** * @Title: PageUtil.java * @Package * @Description: TODO(用一句话描述该文件做什么) * @author licy * @date ...

  10. 【嵌入式硬件Esp32】ESP32学习之在windows下搭建eclipse开发环境

    一.所需工具 由于项目要用ESP32模块进行开发,折腾了下集成开发环境,现将过程记录下来,以便需要的人使用.其中需要的有交叉编译工具,esp-idf示例代码以及C/C++版的eclipse. 交叉编译 ...