Codeforces Round #258 (Div. 2)E(组合数+容斥原理)

E. Devu and Flowers
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Devu wants to decorate his garden with flowers. He has purchased n boxes, where the i-th box contains fi flowers. All flowers in a single box are of the same color (hence they are indistinguishable). Also, no two boxes have flowers of the same color.

Now Devu wants to select exactly s flowers from the boxes to decorate his garden. Devu would like to know, in how many different ways can he select the flowers from each box? Since this number may be very large, he asks you to find the number modulo (109 + 7).

Devu considers two ways different if there is at least one box from which different number of flowers are selected in these two ways.

Input

The first line of input contains two space-separated integers n and s (1 ≤ n ≤ 200 ≤ s ≤ 1014).

The second line contains n space-separated integers f1, f2, ... fn (0 ≤ fi ≤ 1012).

Output

Output a single integer — the number of ways in which Devu can select the flowers modulo (109 + 7).

Sample test(s)
input
2 3
1 3
output
2
input
2 4
2 2
output
1
input
3 5
1 3 2
output
3

题意:给出n种花,以及每种花的数量 a[i] ,然后要求从中选出s束花,问有多少种选法

思路:首先我们先不考虑每种花会超出数量的情况,那么一共是C(s+n-1,n-1)种选法,现在假设在一些方案里面第i种花选的超出了所给的最大数量那么就要减去C(s+n-1-

         a[i]-1,n-1),同时这样减可能会减多一些可能的方案,那么还要加回来,可以采用容斥原理,有偶数种花超出了就+,奇数就减,因为n最大只有20,可以状态压缩,1表

         示超出,0表示未超出,暴力计算完就好了~

你可能感兴趣的:(ACM,codeforces)