C. Kyoya and Colored Balls(Codeforces Round #309 (Div. 2))

C. Kyoya and Colored Balls

Kyoya Ootori has a bag with n colored balls that are colored with k different
colors. The colors are labeled from 1 to k.
Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color ibefore
drawing the last ball of color i?+?1 for all i from 1 to k?-?1.
Now he wonders how many different ways this can happen.

Input

The first line of input will have one integer k (1?≤?k?≤?1000)
the number of colors.

Then, k lines will follow. The i-th
line will contain ci,
the number of balls of the i-th color (1?≤?ci?≤?1000).

The total number of balls doesn‘t exceed 1000.

Output

A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1?000?000?007.

Sample test(s)

input

3
2
2
1

output

3

input

4
1
2
3
4

output

1680

Note

In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are:

1 2 1 2 3
1 1 2 2 3
2 1 1 2 3
时间: 2024-10-10 09:06:10

C. Kyoya and Colored Balls(Codeforces Round #309 (Div. 2))的相关文章

A. Kyoya and Photobooks(Codeforces Round #309 (Div. 2))

A. Kyoya and Photobooks Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photo

找规律 Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks

题目传送门 1 /* 2 找规律,水 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 using namespace std; 10 11 const int MAXN = 1e4 + 10; 12 const int INF = 0x3f3f3f3f; 13 char s

贪心 Codeforces Round #309 (Div. 2) B. Ohana Cleans Up

题目传送门 1 /* 2 题意:某几列的数字翻转,使得某些行全为1,求出最多能有几行 3 想了好久都没有思路,看了代码才知道不用蠢办法,匹配初始相同的行最多能有几对就好了,不必翻转 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <string> 8 #include <cmath> 9 #include <iostream> 10 using namespace std; 1

Codeforces Round #309 (Div. 2)

A. Kyoya and Colored Balls 一个背包有K种颜色一共N个球,颜色分别为1,2,3...K,颜色相同的球是不区别的.现在从背包里一个一个拿球直到所有球拿光,在拿光第I+1种颜色球之前一定要拿光第I种颜色的球,求有多少种拿法 如 果只有一种颜色的球,拿的方法只有一种.如果有两种,留下一个颜色为2的放在最后一个,剩下的N1个颜色1和N2-1个颜色2的可以随意摆,方法数为 1*\(N1+N2-1 \choose N2-1\):如果有三种相当于先排好颜色为1,2的,然后剩下N3-1

Codeforces Round #309 (Div. 2) C. Kyoya and Colored Balls

Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he

B. Ohana Cleans Up(Codeforces Round #309 (Div. 2))

B. Ohana Cleans Up Ohana Matsumae is trying to clean a room, which is divided up into an n by n grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she swe

Codeforces Round #309 (Div. 2) C

题意: 就是给出总共有k种颜色,每种颜色有ki种,排列必须满足第i+1种的最后一种颜色必须在第i种最后一种颜色的后面,其他颜色随意.总共有多少种排列点的方法. 分析: 假设d[i]表示前i种的排列的数量,那么第i+1种的数量就是d[i]*C(a[1]+a[2]+..a[i+1]-1,a[i+1]-1);预先处理好排列组合数就好了,直接计算. ps:CF的比赛时间还真是有点烦,话说我一直不明白为什么我看电视能坚持到两点,打CF就不行呢?于是我就边看电视边打CF~哈哈哈哈 #include <cst

Codeforces A. Kyoya and Colored Balls(分步组合)

题目描述: Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled f

CF R309C 554C Kyoya and Colored Balls

554C Kyoya and Colored Balls 即求 复合条件的序列数量 序列最后一位必定是K. 那么对于c[k]-1个剩下的K,有n-1个位置去放置. 同理,对于颜色为k-1的球 在剩下的n-c[k]个位置中,必有一个在最靠右的空位置上. 剩下的c[k-1]-1个球放在剩下的位置上 类推 core code: while(k--){ res *= C[n-1][c[k]-1]%MOD; n -= c[k]; }