这个题是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的更多相关文章

  1. Educational Codeforces Round 46 (Rated for Div. 2) E. We Need More Bosses

    Bryce1010模板 http://codeforces.com/contest/1000/problem/E 题意: 给一个无向图,求图的最长直径. 思路:对无向图缩点以后,求图的最长直径 #in ...

  2. Educational Codeforces Round 46 (Rated for Div. 2) C. Covered Points Count

    Bryce1010模板 http://codeforces.com/problemset/problem/1000/C 题意:问你从[l,r]区间的被多少条线覆盖,列出所有答案. 思路:类似括号匹配的 ...

  3. Educational Codeforces Round 46 (Rated for Div. 2) B. Light It Up

    Bryce1010模板 http://codeforces.com/problemset/problem/1000/B 思路:先用两个数组sumon[]和sumoff[]将亮着的灯和灭的灯累计一下. ...

  4. Educational Codeforces Round 46 (Rated for Div. 2) A. Codehorses T-shirts

    Bryce1010模板 http://codeforces.com/problemset/problem/1000/A 题意: 问你将一种类型的衣服转换成另一种的最小次数. #include<b ...

  5. Educational Codeforces Round 46 (Rated for Div. 2)

    A - Codehorses T-shirts 思路:有相同抵消,没有相同的对答案+1 #include<bits/stdc++.h> #define LL long long #defi ...

  6. Educational Codeforces Round 46 (Rated for Div. 2) D

    dp[i]表示一定包含第I个点的好的子序列个数,那么最终答案就是求dp[0] + dp[1] + .... + dp[n-1] 最终的子序列被分成了很多块,因此很明显我们枚举第一块,第一块和剩下的再去 ...

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

  8. Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序

    Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序 [Problem Description] ​ 给你 ...

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

随机推荐

  1. Oracle 12c logminer测试

    首先开启归档:SQL> archive log list   Database log mode              Archive ModeAutomatic archival     ...

  2. 如何退出virtualbox scale mode

    进入scale mode之后,可能会退不出来 HOST Key + C. 默认是 右Ctrl + C

  3. Hbase集群部署及shell操作

    本文详述了Hbase集群的部署. 集群部署 1.将安装包上传到集群并解压 scp hbase-0.99.2-bin.tar.gz mini1:/root/apps/ tar -zxvf hbase-0 ...

  4. Software Architecture

    Software Architecture Architecture serves as a blueprint for a system. It provides an abstraction to ...

  5. Codeforces Round #540 (Div. 3) C. Palindromic Matrix 【暴力】

    任意门:http://codeforces.com/contest/1118/problem/C C. Palindromic Matrix time limit per test 2 seconds ...

  6. 理解HTML DOM

    DOM(Document Object Model)全称文档对象模型.DOM其实是JavaScript操作网页的一套API接口,定义了访问和操作HTML文档的标准.定义了所有HTML元素的对象和属性, ...

  7. 使用Nginx 做负载均衡

    Nginx可以作为一个非常高效的负载均衡系统,通过分发HTTP请求到多个应用服务器来提高整个系统的吞吐量,性能和可用性. 负载均衡的算法/机制 下面是Nginx支持的机制 轮询机制 轮询算法 最少连接 ...

  8. ListView 中嵌套 GridView

    1.主布局文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andr ...

  9. jquery遍历数组

    示例: ajax返回的数组进行遍历 $.ajax({ type:"POST", url:"<?php echo base_url(); ?>public_re ...

  10. Notes 20180308 : 语句

    在讲解流程控制语句之前,我们先来说一下语句的问题.Java中的语句分为声明和赋值语句,条件和循环语句,调用和返回语句:我们之所以每两个放在一起是有深意的,我们大致将语句分为这三块,并以此为纲来说一下, ...