logo AlgoBeat OnlineJudge
登录 注册

#102274. [BZOJ 2274] [Usaco2011 Feb]Generic Cow Protests

内存限制:128 MiB 时间限制:10000 ms 标准输入输出
题目类型:传统 评测方式:文本比较
上传者: 匿名

题目描述

Farmer John's cows are lined up in a row and numbered .The cows are conducting another one of their strange protests,so each cow is holding up a sign with an integer

FJ knows the mob of cows will behave if they are properly grouped and thus would like to arrange the cows into one or more contiguous groups so that every cow is in exactly one group and that every group has a nonnegative sum.

Help him count the number of ways he can do this,modulo

By way of example,if and the cows' signs are ,and ,then the following are the only four valid ways of arranging the cows:

( )

( ) ()

() ( )

() ( ) ()

Note that this example demonstrates the rule for counting different orders of the arrangements.

给出 个数,问有几种划分方案(不能改变数的位置),使得每组中数的和大于等于 。输出方案数除以 的余数。

输入格式

  • Line :A single integer:

  • Lines :Line contains a single integer:

输出格式

  • Line :A single integer,the number of arrangements modulo

样例

样例输入 #1

4
2
3
-3
1

样例输出 #1

4

数据范围与提示

Gold

的数据满足: