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 i before 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, modulo1 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 有n个小球,有k种颜色,编号为1~k,每一个小球都被染了一种颜色,
numi表示颜色为i的颜色的球有numi个。
num之和=n
现在问你这n个小球有多少种排列方式,满足第i种颜色的最后一个球后面的球的颜色一定是i+1(1<=i<n) 分析,
先考虑第k种颜色的球,一定有一个第k种颜色的球是放在最后的位置了
 #include<cstdio>
#include<cstring> using namespace std; #define ll long long const int maxn=+;
const int mod=1e9+; ll fac[maxn];
ll num[]; inline ll quick_pow(ll x)
{
ll y=mod-;
ll ret=;
while(y){
if(y&){
ret=ret*x%mod;
}
x=x*x%mod;
y>>=;
}
return ret;
} int main()
{
fac[]=;
for(int i=;i<maxn;i++){
fac[i]=(fac[i-]*i)%mod;
}
int k;
scanf("%d",&k);
ll sum=;
for(int i=;i<=k;i++){
scanf("%I64d",&num[i]);
sum+=num[i];
}
ll ans=; for(int i=k;i>=;i--){
ans*=fac[sum-]*quick_pow(((fac[num[i]-]%mod)*(fac[sum-num[i]]%mod))%mod)%mod;
ans%=mod;
sum-=num[i];
}
printf("%I64d\n",ans); return ;
}

最新文章

  1. C#变量详解
  2. RIDE安装遇到的问题及解决方法
  3. window.location.href 失效的解决办法
  4. Redis系列(二)—— 数据类型及其使用
  5. OpenXml入门----给Word文档添加表格
  6. 微信公众平台开发接口PHP SDK完整版
  7. Hibernate的Restrictions用法
  8. POJ 1279 Art Gallery(半平面交求多边形核的面积)
  9. 内存中的static、const实现形式
  10. Sybase数据库异常紧急恢复
  11. C#中打日志导出日志到txt文本
  12. qml 静态编译程序执行错误 无法定位程序输入点 CreateDXGIFactory2 于动态链接库 dxgi.dll 上
  13. iOS中 Swift初级入门学习(一)
  14. DDctf 新得
  15. 前后端分离djangorestframework—— 接入支付宝支付平台
  16. 题解 UVA1567 【A simple stone game】
  17. go语言开发教程之web项目开发实战
  18. (一)为什么要UML
  19. JavaScript:变量提升和函数提升
  20. linux下kill -9 pid 强制不能杀掉进程原因

热门文章

  1. windows下AppServ安装php的memcached扩展
  2. 黑马程序员——JAVA基础之set集合
  3. Java设计模式之责任链设计模式
  4. ps白平衡
  5. java performance
  6. CentOS如何挂载硬盘
  7. 简单实用的Android ORM框架TigerDB
  8. 015. asp.net实现简易聊天室
  9. 使用JavaScript根据从后台获取来的数据打开一个新的页面
  10. 【转】Javascript+css 实现网页换肤功能