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
  1. 3
  2. 2
  3. 2
  4. 1
output
  1. 3
input
  1. 4
  2. 1
  3. 2
  4. 3
  5. 4
output
  1. 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. 1 2 1 2 3
  2. 1 1 2 2 3
  3.  
  4. 2 1 1 2 3
  5.  
  6. 这道题让我学会了组合数的计算。由于直接用组合数公式会导致结果不准确。如C(100,50)这样,假设用乘一个数除一个数的方法,那么可能会导致不能整除而会发生误差。
  7.  
  8. 思路:若前i种颜色的方法总数是f(i),那么第i+1种颜色的方法总数是f(i+1)=f(i)*C(sum(i+1)-1,a[i+1]-1),当中sum(i+1)是前i+1种颜色的个数总和。
  9.  
  10.  
  11. #include<stdio.h>
  12. #include<string.h>
  13. #include<iostream>
  14. #include<string>
  15. #include<map>
  16. #include<algorithm>
  17. using namespace std;
  18. #define ll __int64
  19. #define maxn 1000000007
  20. int a[1600];
  21. ll c[1050][1060];
  22. ll sum;
  23. int main()
  24. {
  25. 	int n,m,i,j,sum1;
  26. 	for(i=1;i<=1000;i++)c[i][0]=1;
  27. 	for(i=1;i<=1000;i++){
  28. 		for(j=1;j<=i;j++){
  29. 			if(i==j)c[i][j]=1;
  30. 			else if(i>j)
  31. 			c[i][j]=(c[i-1][j]+c[i-1][j-1])%maxn;
  32. 		}
  33. 	}
  34. 	while(scanf("%d",&n)!=EOF)
  35. 	{
  36. 		for(i=1;i<=n;i++){
  37. 			scanf("%d",&a[i]);
  38. 		}
  39. 		sum1=a[1];sum=1;
  40. 		for(i=2;i<=n;i++){
  41. 			sum1+=a[i];
  42. 			//printf("%d %d\n",a[i]-1,sum1-1);
  43. 			sum=(sum*c[sum1-1][a[i]-1])%maxn;
  44. 			//sum=(sum*f(a[i]-1,sum1-1))%maxn;
  45. 			//printf("%lld\n",sum);
  46. 		}
  47. 		printf("%I64d\n",sum);
  48. 	}
  49. 	return 0;
  50. }

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

  1. Codeforces Round #309 (Div. 2) C. Kyoya and Colored Balls 排列组合

    C. Kyoya and Colored Balls Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

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

    题目传送门 /* 找规律,水 */ #include <cstdio> #include <iostream> #include <algorithm> #incl ...

  3. Codeforces Round #309 (Div. 1) B. Kyoya and Permutation 构造

    B. Kyoya and Permutation Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...

  4. Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks 字符串水题

    A. Kyoya and Photobooks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  5. Codeforces Round #309 (Div. 2) -D. Kyoya and Permutation

    Kyoya and Permutation 这题想了好久才写出来,没看题解写出来的感觉真的好爽啊!!! 题目大意:题意我看了好久才懂,就是给你一个序列,比如[4, 1, 6, 2, 5, 3],第一个 ...

  6. Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks【*组合数学】

    A. Kyoya and Photobooks time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

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

    题目传送门 /* 题意:某几列的数字翻转,使得某些行全为1,求出最多能有几行 想了好久都没有思路,看了代码才知道不用蠢办法,匹配初始相同的行最多能有几对就好了,不必翻转 */ #include < ...

  8. 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 diffe ...

  9. Codeforces Round #309 (Div. 2)

    A. Kyoya and Photobooks Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He ha ...

随机推荐

  1. Oracle 函数 “自动生成订单号”

    create or replace function get_request_code return varchar2 AS --函数的作用:自动生成订单号 v_mca_no mcode_apply_ ...

  2. PreparedStatement 查询 In 语句 setArray 等介绍。

    ps = conn.prepareStatement("SELECT tid,jdp_response FROM jdp_tb_trade WHERE tid IN (?) ORDER BY ...

  3. opencv(1)图像处理

    2.图像操作 图片裁剪 裁剪是利用array自身的下标截取实现 HSV空间 除了区域,图像本身的属性操作也非常多,比如可以通过HSV空间对色调和明暗进行调节.HSV空间是由美国的图形学专家A. R. ...

  4. TypeScript 2 : 获取当前日期及前后范围日期【Array】

    前言 今天有个接口字段需求,要写一个今天及前几天的日期传过去: 在网上找了下都木有什么比较好的方案:就自己写了一个. 因为技术栈就是NG2+TS2+WEBPACK,这里的代码需要一定的TS2及ES6的 ...

  5. 日志、字段备注查询、自增ID联系设置、常用存储过程

    -----获取数据字典SQL(表字段说明)SELECT     [Table Name] = OBJECT_NAME(c.object_id),     [Column Name] = c.name, ...

  6. Effective STL 学习笔记:19 ~ 20

    Effective STL 学习笔记:19 ~ 20 */--> div.org-src-container { font-size: 85%; font-family: monospace; ...

  7. hdu 1171 有num1个w1 , num2个w2 ……. (母函数)

    输入n,代表学院里面有n种设备,并且在下面输入n行,每一行输入v,m代表设备的价格为v,设备的数量是m.然后要求把这些设备的总价值分摊,尽量平分,使其总价值接近相等,最好是相等 比如样例二(1+X10 ...

  8. 解决ASP.NET MVC(post数据)Json请求太大,无法反序列化(The JSON request was too large to be deserialized)

    这个问题出现的场景并不是很多,当你向服务端异步(ajax)post数据非常大的情况下(比如做权限管理的时候给某个角色分配权限那么就可能会出现,我所遇到的就是该角色大概200个模块每个模块平均2个功能- ...

  9. 【POJ】1740.A New Stone Game

    题解 想去学习一下博弈论的SG函数 不过貌似这道题就是猜结论并且证明 题意是,随便选择一堆石子,扔掉至少一个,然后从扔石子的这堆里选择任意多(可以不选)放到其他任意多的未选择完的石堆里 一堆石子,先手 ...

  10. python之web框架(2):了解WSGI接口

    python之web框架(2):了解WSGI接口 1.什么是wsgi接口: wsgi:Web Service Gateway Interface.它不是模块,而只是一种规范,方便web服务器和各种框架 ...