Yet Another Problem On a Subsequence CodeForces - 1000D (组合计数)
大意:定义一个长为$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 (组合计数)的更多相关文章
- 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 ...
- Anton and School - 2 CodeForces - 785D (组合计数,括号匹配)
大意: 给定括号字符串, 求多少个子序列是RSGS. RSGS定义如下: It is not empty (that is n ≠ 0). The length of the sequence is ...
- Different Subsets For All Tuples CodeForces - 660E (组合计数)
大意: 定义$f(a)$表示序列$a$本质不同子序列个数. 给定$n,m$, 求所有长$n$元素范围$[1,m]$的序列的$f$值之和. 显然长度相同的子序列贡献是相同的. 不考虑空串, 假设长$x$ ...
- Singer House CodeForces - 830D (组合计数,dp)
大意: 一个$k$层完全二叉树, 每个节点向它祖先连边, 就得到一个$k$房子, 求$k$房子的所有简单路径数. $DP$好题. 首先设$dp_{i,j}$表示$i$房子, 分出$j$条简单路径的方案 ...
- Intercity Travelling CodeForces - 1009E (组合计数)
大意: 有一段$n$千米的路, 每一次走$1$千米, 每走完一次可以休息一次, 每连续走$x$次, 消耗$a[1]+...+a[x]$的能量. 休息随机, 求消耗能量的期望$\times 2^{n-1 ...
- GukiZ and Binary Operations CodeForces - 551D (组合计数)
大意: 给定$n,k,l,m$, 求有多少个长度为$n$, 元素全部严格小于$2^l$, 且满足 的序列. 刚开始想着暴力枚举当前or和上一个数二进制中$1$的分布, 但这样状态数是$O(64^3)$ ...
- 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 ...
- Consecutive Subsequence CodeForces - 977F(dp)
Consecutive Subsequence CodeForces - 977F 题目大意:输出一序列中的最大的连续数列的长度和与其对应的下标(连续是指 7 8 9这样的数列) 解题思路: 状态:把 ...
- D. Yet Another Problem On a Subsequence 解析(DP)
Codeforce 1000 D. Yet Another Problem On a Subsequence 解析(DP) 今天我們來看看CF1000D 題目連結 題目 略,請直接看原題 前言 這題提 ...
随机推荐
- 【spark core学习---算子总结(java版本) (第1部分)】
map算子 flatMap算子 mapParitions算子 filter算子 mapParttionsWithIndex算子 sample算子 distinct算子 groupByKey算子 red ...
- The implementation of iterators in C# and its consequences (part 1) Raymond Chen
Likeanonymous methods, iterators in C# are very complex syntactic sugar. You could do it all yoursel ...
- tornado异步请求响应速度的实例测试
tornado异步请求响应速度的实例测试
- setShadpwLayer实现阴影效果
package com.loaderman.customviewdemo; import android.content.Context; import android.graphics.*; imp ...
- iOS-UIScrollView+UIPageControl简单实现
#import "MJViewController.h"#import "RootViewController.h" @interface MJViewCont ...
- SQL Server数据同步交换
一.为了解决数据同步汇聚,数据分发,数据转换,数据维护等需求,TreeSoft将复杂的网状的同步链路变成了星型数据链路. TreeSoft作为中间传输载体负责连接各种数据源,为各种异构数据库之 ...
- Redis源码解析
一.src/server.c 中的redisCommandTable列出的所有redis支持的命令,其中字符串命令包括从get到mget:列表命令从rpush到rpoplpush:集合命令包括从sad ...
- charles 文件菜单总结
本文参考:charles 文件菜单总结 一.file(文件菜单) 需要注意的是 "导入"和"导出"这个功能在和别人沟通的时候用, 比如你向第三方工具/类库开发人 ...
- 🔥Scratch少儿编程——飞机大战
前两天用
- Burpsuite—渗透测试神器
Google浏览器插件---SwitchyOmega Firefox浏览器插件---SwitchyOmega hosts代理工具---SwitchHosts[右击使用管理员权限打开] 双击burp-l ...