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 ...
随机推荐
- typeof操作符和instanceof操作符的区别 标签: JavaScript 2016-08-01 14:21 113人阅读 评论(
typeof主要用于检测变量是不是基本数据类型 typeof操作符是确定一个变量是字符串.数值.布尔类型,还是undefined的最佳工具.此外,使用typeof操作符检测函数时,会返回"f ...
- ZT 七大寡头
网易评论人才辈出啊!!!看下面 http://comment.news.163.com/news_guoji2_bbs/9GRIIJA90001121M.html 关注 关注他的微博yftyfm ...
- 在Node中使用ES7新特征——async、await
async与await两个关键字是在ES7中添加的新特征,旨在更加直观的书写异步函数,避免出现callback hell. callback hell是什么? readFileContents(&qu ...
- Java虚拟机5:常用JVM命令参数
这里汇总一些平时用到的.看到的一些虚拟机参数: (1)-Xms20M 表示设置堆容量的最小值为20M,必须以M为单位 (2)-Xmx20M 表示设置堆容量的最大值为20M,必须以M为单位.将-Xmx和 ...
- Django 玩转API
现在,让我们进入Python的交互式shell,玩转这些Django提供给你的API. 使用如下命令来调用Python shell: $ python manage.py shell 我们使用上述命令 ...
- UIView 动画 依赖与 CALayer的证据
- (nullable id<CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event Layer: -(voi ...
- UVa 11082 - Matrix Decompressing(最大流)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- BZOJ4530:[BJOI2014]大融合(LCT)
Description 小强要在N个孤立的星球上建立起一套通信系统.这套通信系统就是连接N个点的一个树. 这个树的边是一条一条添加上去的.在某个时刻,一条边的负载就是它所在的当前能够 联通的树上路过它 ...
- 【转】Android开发:shape和selector和layer-list的(详细说明)
<shape>和<selector>在Android UI设计中经常用到.比如我们要自定义一个圆角Button,点击Button有些效果的变化,就要用到<shape> ...
- canny算子求图像边缘,edgebox那部分
过程: 1. 彩色图像转换为灰度图像 2. 对图像进行高斯模糊 3. 计算图像梯度,根据梯度计算图像边缘幅值与角度(这里其实用到了微分边缘检测算子来计算梯度幅 ...