bzoj#P2274. [Usaco2011 Feb]Generic Cow Protests

[Usaco2011 Feb]Generic Cow Protests

题目描述

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

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 1×10991 \times 10^9+9

By way of example,if N=4N = 4 and the cows' signs are 2,3,32,3,-3,and 11,then the following are the only four valid ways of arranging the cows:

(22 33 3-3 11)

(22 33 3-3) (11)

(22) (33 3-3 11)

(22) (33 3-3) (11)

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

给出 nn 个数,问有几种划分方案(不能改变数的位置),使得每组中数的和大于等于 00。输出方案数除以 1×10991 \times 10^9+9 的余数。

输入格式

  • Line 11:A single integer:NN

  • Lines 2×N+12 \times N + 1:Line i+1i + 1 contains a single integer:AiA_i

输出格式

  • Line 11:A single integer,the number of arrangements modulo 1×10991 \times 10^9+9
4
2
3
-3
1
4

题目来源

Gold

数据规模与约定

100%100\% 的数据满足:1N1×1051 \le N \le 1 \times 10^51×104Ai1×104-1 \times 10^4 \le A_i \le 1 \times 10^4