CF1000D.Yet Another Problem On a Subsequence
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The sequence of integers a1,a2,…,ak is called a good array if a1=k−1 and a1>0. For example, the sequences [3,−1,44,0],[1,−99] are good arrays, and the sequences [3,7,8],[2,5,4,1],[0] — are not.
A sequence of integers is called good if it can be divided into a positive number of good arrays. Each good array should be a subsegment of sequence and each element of the sequence should belong to exactly one array. For example, the sequences [2,−3,0,1,4], [1,2,3,−3,−9,4] are good, and the sequences [2,−3,0,1], [1,2,3,−3−9,4,1] — are not.
For a given sequence of numbers, count the number of its subsequences that are good sequences, and print the number of such subsequences modulo 998244353.
整数序列 a1,a2,…,ak 被称为好数组,当且仅当 a1=k−1 且 a1>0。例如,序列 [3,−1,44,0]、[1,−99] 是好数组;而序列 [3,7,8]、[2,5,4,1]、[0] 则不是。
一个整数序列被称为好序列,当且仅当它可以被划分为若干个(正整数个)好数组。每个好数组必须是该序列的一个连续子段,且序列中的每个元素恰好属于其中一个好数组。例如,序列 [2,−3,0,1,4]、[1,2,3,−3,−9,4] 是好序列;而序列 [2,−3,0,1]、[1,2,3,−3−9,4,1] 则不是。
给定一个整数序列,求其所有子序列中是好序列的个数,并将结果对 998244353 取模后输出。
输入格式
The first line contains the number n (1≤n≤103) — the length of the initial sequence. The following line contains n integers a1,a2,…,an (−109≤ai≤109) — the sequence itself.
第一行包含一个整数 n (1≤n≤103) —— 初始序列的长度。
接下来的一行包含 n 个整数 a1,a2,…,an (−109≤ai≤109) —— 序列本身。
输出格式
In the single line output one integer — the number of subsequences of the original sequence that are good sequences, taken modulo 998244353.
在单行输出一个整数——原序列中“好序列”子序列的个数,对 998244353 取模。
输入输出样例
输入#1
3 2 1 1
输出#1
2
输入#2
4 1 1 1 1
输出#2
7
说明/提示
In the first test case, two good subsequences — [a1,a2,a3] and [a2,a3].
In the second test case, seven good subsequences — [a1,a2,a3,a4],[a1,a2],[a1,a3],[a1,a4],[a2,a3],[a2,a4] and [a3,a4].
在第一个测试用例中,有两个好数组:[a1,a2,a3] 和 [a2,a3]。
在第二个测试用例中,有七个好数组:[a1,a2,a3,a4],[a1,a2],[a1,a3],[a1,a4],[a2,a3],[a2,a4] 和 [a3,a4]。
输入解题思路,AI测评打分。不知道怎么写?