Educational Codeforces Round 46 (Rated for Div. 2) D. Yet Another Problem On a Subsequence
这个题是dp, dp[i]代表以i开始的符合要求的字符串数
j是我们列举出的i之后一个字符串的开始地址,这里的C是组合数
dp[i] += C(j - i - 1, A[i]] )* dp[j];
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
const int N = 1e3 + 5;
typedef long long ll;
using namespace std;
const int MOD = 998244353;
int A[N];
ll dp[N];
ll C[N][N];
int main() {
int n;
C[0][0] = 1;
for(int i = 1; i < N; ++i) {
C[i][0] = 1; C[i][i] = 1;
for(int j = 1; j <= i/2; ++j) {
C[i][j] = C[i][i-j] = (C[i-1][j-1] + C[i-1][j]) % MOD;
}
}
while(~scanf("%d", &n)) {
for(int i = 1; i <= n; ++i) {
scanf("%d", &A[i]);
}
memset(dp, 0, sizeof(dp));
dp[n + 1] = 1;
for(int i = n; i >= 1; --i) {
int edpos = i + A[i] + 1;
if(A[i] > 0 && edpos <= n+1) {
for(int j = edpos; j <= n+1; ++j) {
// printf("%d %d\n", i, j);
dp[i] = (dp[i] + C[j - i - 1][A[i]] * dp[j] % MOD ) % MOD;
}
}
// printf("hh %d %d\n", i, dp[i]);
}
ll ans = 0;
for(int i = 1; i <= n; ++i) {
ans = (ans + dp[i]) % MOD;
}
printf("%lld\n", ans);
}
return 0;
}
Educational Codeforces Round 46 (Rated for Div. 2) D. Yet Another Problem On a Subsequence的更多相关文章
- Educational Codeforces Round 46 (Rated for Div. 2) E. We Need More Bosses
Bryce1010模板 http://codeforces.com/contest/1000/problem/E 题意: 给一个无向图,求图的最长直径. 思路:对无向图缩点以后,求图的最长直径 #in ...
- Educational Codeforces Round 46 (Rated for Div. 2) C. Covered Points Count
Bryce1010模板 http://codeforces.com/problemset/problem/1000/C 题意:问你从[l,r]区间的被多少条线覆盖,列出所有答案. 思路:类似括号匹配的 ...
- Educational Codeforces Round 46 (Rated for Div. 2) B. Light It Up
Bryce1010模板 http://codeforces.com/problemset/problem/1000/B 思路:先用两个数组sumon[]和sumoff[]将亮着的灯和灭的灯累计一下. ...
- Educational Codeforces Round 46 (Rated for Div. 2) A. Codehorses T-shirts
Bryce1010模板 http://codeforces.com/problemset/problem/1000/A 题意: 问你将一种类型的衣服转换成另一种的最小次数. #include<b ...
- Educational Codeforces Round 46 (Rated for Div. 2)
A - Codehorses T-shirts 思路:有相同抵消,没有相同的对答案+1 #include<bits/stdc++.h> #define LL long long #defi ...
- Educational Codeforces Round 46 (Rated for Div. 2) D
dp[i]表示一定包含第I个点的好的子序列个数,那么最终答案就是求dp[0] + dp[1] + .... + dp[n-1] 最终的子序列被分成了很多块,因此很明显我们枚举第一块,第一块和剩下的再去 ...
- Educational Codeforces Round 34 (Rated for Div. 2) A B C D
Educational Codeforces Round 34 (Rated for Div. 2) A Hungry Student Problem 题目链接: http://codeforces. ...
- Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序
Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序 [Problem Description] 给你 ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
随机推荐
- ORACLE_TO_CHAR Function
TECHONTHENNTE WEBSITE: https://www.techonthenet.com/oracle/functions/to_char.php Oracle / PLSQL: TO ...
- kill -9 和kill-15的区别
kill -9大家应该是非常熟悉的,杀死进程一般用kill -9的吧. 今天接触到kill -15,kill -15也是杀死进程的.那个kill -15和kill -9有什么区别呢? 其实kill - ...
- SAP成都研究院2018年总共87篇技术文章合集
2018年很快就要结束了.Jerry在2017年年底准备开始写这个公众号时,给自己定的目标是:2018年至少保证每周发布一篇高质量的文章.如今2018年就快过去了,高质量与否需要大家来反馈,至少从量上 ...
- 简单封装的ajax请求
简单封装了一个ajax请求,做一下统一处理,少写重复代码,只是一个初步的代码,没有经过优化. $.extend({ myAjax: function (option, rollBack) { var ...
- MySQL语法三:数据控制语句
数据控制语句MCL(GRANT,REVOKE,COMMIT,ROLLBACK)
- 博客改用markdown编写啦!
如题,在某谷上交了一篇题解之后,顿时觉得\(markdown\)非常好看.
- JS常用方法封装
迭代添加各种常用方法:项目中一定会有很多常用的方法,包括:取值,校验,等...... 获取 url 后的参数 function getQueryString(name) { var reg = new ...
- idea中ssm自动配置
自动生成 只需要创建好maven项目,然后创建一个类Test,复制代码粘贴即可 使用注意: 代码 import java.io.*; public class Test { //包名格式 //列如配置 ...
- java根据数据库自动生成代码
出现这个已经创建成功 出现这个情况,没有使用DBUtil,引入即可 已经创建完成 代码下载:https://github.com/weibanggang/tool 项目实例下载:https://pan ...
- 如何在.Net Core 2.0 App中读取appsettings.json
This is something that strangely doesn’t seem to be that well documented and took me a while to figu ...