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

dp[i]表示一定包含第I个点的好的子序列个数,那么最终答案就是求dp[0] + dp[1] + .... + dp[n-1]

最终的子序列被分成了很多块,因此很明显我们枚举第一块,第一块和剩下的再去组合,然后我们为了保证没有重复,我们需要保证第一块不同,然而第一块的大小是固定的,因此我们可以选择枚举第一块最后一个数,这样第一块就肯定不会相同了,也可以计算

const ll P = 998244353;

ll dp[maxn];

int N = 1000;

ll comb[maxn][maxn];

int main(){
	for(int i=0;i<=N;i++)
		comb[i][0]=comb[i][i]=1;
	for(int i=2;i<=N;i++)
		for(int j=1;j<N;j++)
			comb[i][j]=(comb[i-1][j]+comb[i-1][j-1])%P;
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0 ; i < n ; i++) {
		cin >> a[i];
	}
	dp[n]=1;
	ll ans=0;
	for(int i = n - 1 ; i >= 0 ; i--){
		if(a[i] <= 0 ) continue;
		ll sum = 0;
		for(int j = n ; j >= i + a[i] + 1 ; j--){
			sum = (sum + dp[j]) % P;
			dp[i] = (dp[i] + comb[j - i - 2][a[i] -1] % P * sum % P) % P;
		}
		//cout<<dp[i]<<endl;
		//cout<<ans<<endl;
		ans= (ans+dp[i]) %P;
	}
	cout<<ans<<endl;
	return 0;
}

  

原文地址:https://www.cnblogs.com/033000-/p/12322668.html

时间: 2024-10-11 16:48:37

Educational Codeforces Round 46 (Rated for Div. 2) D的相关文章

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 &

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

题目链接:E. We Need More Bosses 题解:tarjan有向图缩点之后求树的直径就是答案:应为在同一个强联通里的边就不是必须边,参考了这个 #include<bits/stdc++.h> #include<set> #include<cstdio> #include<iomanip> #include<iostream> #include<string> #include<cstring> #includ

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai. You can move these disks

Educational Codeforces Round 71 (Rated for Div. 2) A - There Are Two Types Of Burgers

原文链接:https://www.cnblogs.com/xwl3109377858/p/11404050.html Educational Codeforces Round 71 (Rated for Div. 2) A - There Are Two Types Of Burgers There are two types of burgers in your restaurant — hamburgers and chicken burgers! To assemble a hamburg

Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations

原文链接:https://www.cnblogs.com/xwl3109377858/p/11405773.html Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations You are given a sequence of n pairs of integers: (a1,b1),(a2,b2),…,(an,bn). This sequence is called bad if it is

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

Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序 [Problem Description] ? 给你一个有向图,给用最少的颜色给每条边染色,要保证不存在一个环中的所有边都是同一个颜色. [Solution] ? 用拓扑排序判断图中是否存在环,若图中不存在环,则所有边都是同一种颜色.否则,同一个环中,只要用两种颜色就可以满足题目条件,所以总的颜色数就是两种,对于一个环,一定会存在两种边:1.节点号小

Educational Codeforces Round 36 (Rated for Div. 2) 题解

Educational Codeforces Round 36 (Rated for Div. 2) 题目的质量很不错(不看题解做不出来,笑 Codeforces 920C 题意 给定一个\(1\)到\(n\)组成的数组,只可以交换某些相邻的位置,问是否可以将数组调整为升序的 解题思路 首先如果每个数都能通过交换到它应该到的位置,那么就可以调整为升序的. 但实际上交换是对称的,如果应该在的位置在当前位置前方的数都交换完成,那么整体就是排好序的,因为不可能所有不在相应位置的数都在相应位置的后方.

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://codeforces.com/contest/985/problem/E Description Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome w