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.

Input

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.

Output

In the single line output one integer — the number of subsequences of the original sequence that are good sequences, taken modulo 998244353.

Examples

Input
3
2 1 1
Output
2
Input
4
1 1 1 1
Output
7

Note

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

题意 : 给你一串数字,并按照题目叙述,给出一个好序列的定义,并且任意个好序列之间可以合并起来,问最终好序列的个数。

思路分析:

  dp[i] 表示以i位置开始的序列的最优解,倒着推一下就可以了, dp[i] += dp[j-i][i]*dp[j+1] (i+a[i] <= j <= n)

代码示例:

ll n;
ll a[1005];
ll c[1005][1005]; void init(){
for(ll i = 1; i <= 1000; i++){
c[i][0] = c[i][i] = 1;
for(ll j = 1; j < i; j++){
c[i][j] = (c[i-1][j]+c[i-1][j-1])%mod;
}
}
}
ll dp[1005]; int main() {
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
init(); cin >> n;
for(ll i = 1; i <= n; i++){
scanf("%lld", &a[i]);
}
dp[n+1] = 1; ll ans = 0;
for(ll i = n-1; i >= 1; i--){
ll p = i+a[i];
if (a[i] <= 0) continue;
for(ll j = p; j <= n; j++){
dp[i] += (c[j-i][a[i]]*dp[j+1])%mod;
dp[i] %= mod;
}
ans += dp[i];
ans %= mod;
}
printf("%lld\n", ans); return 0;
}

最新文章

  1. mybatis输出SQL
  2. android驱动开发前的准备(五)
  3. Nova: 虚机的块设备总结 [Nova Instance Block Device]
  4. paip.提升分词---准确度--常用量词表
  5. 【使用 DOM】使用 Window 对象
  6. Linux 基础知识----shell
  7. eclipse有生成不带参数的构造方法的快捷键吗
  8. UDP TCP 消息边界
  9. VBA在EXCEL中创建图形线条
  10. OPNET安装要点
  11. BZOJ 3572 世界树(虚树)
  12. Knockout应用开发指南 第十章:更多信息(完结篇)
  13. vsftp虚拟主机
  14. HDFS概述(5)————HDFS HA
  15. 详解Office 外接程序 COM Add In的LoadBehavior及其妙用
  16. WebService学习--(三)使用JDK开发WebService
  17. MySQL 笔记整理(10) --MySQL为什么有时会选错索引?
  18. Redis事务涉及的watch、multi等命令
  19. TCP/IP ARP
  20. 转 python测试框架最全资源汇总

热门文章

  1. Java中的元注解
  2. eslint在webstorm中有错误警告
  3. Koa搭建简单服务器
  4. 字符串和While循环
  5. CF1208
  6. [USACO10OCT]Lake Counting(DFS)
  7. 深入Oracle的left join中on和where的区别详解
  8. Hibernate映射文件详解(News***.hbm.xml)一
  9. JVM内存结构探秘及编码实战
  10. 0008 CSS初识(行内式、内部样式表、外部样式表)