F. 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 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.

Examples
input

Copy
3
2
2
1
output

Copy
3
input

Copy
4
1
2
3
4
output

Copy
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种颜色的球,同种颜色的球视为完全相同,设置一种放置规则,即上一种颜色球的最后一个必须放在当前颜色球最后一个的前面,问放球的方案数。
题解:
把情况分开考虑,一种颜色一种颜色的往上放,那么dp[i]表示已经放了i种颜色的方案数,a[i]表示第i种颜色的球的个数,sum[i]表示前i种球一共有这么多个,所以当放入i-1种颜色的球后,要把第i种球放一个到最后面以满足题意,然后向前插球,即当前一共有sum[i-1]+a[i]-1个位置,要在这些位置中找a[i]-1个位置放剩下的第i种球,那么这种操作的方法数就是c[sum[i-1+a[i]-1]][a[i]-1]
#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 1010
#define mod 1000000007
using namespace std;
int n,a[maxn],c[maxn][maxn],dp[maxn],sum[maxn];
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
sum[i]=sum[i-]+a[i];
}
c[][]=;
for(int i=;i<=;i++){
c[i][]=;
for(int j=;j<=;j++)
c[i][j]=(c[i-][j-]+c[i-][j])%mod;
}
dp[]=;
for(int i=;i<=n;i++)
dp[i]=1LL*dp[i-]*c[a[i]-+sum[i-]][a[i]-]%mod;
printf("%d\n",dp[n]);
return ;
}

最新文章

  1. JavaScript中的this指向
  2. AndroidDevTools简介
  3. DOM元素尺寸和位置
  4. wpf4 文字 模糊 不清晰 解决方法
  5. android 通过eclipse混淆代码 打包 + proguard 总结
  6. Android面试,IntentService的原理及使用
  7. android中发送邮件
  8. Express安装入门与模版引擎ejs
  9. Linux中一些简单命令(一)
  10. 【JAVA】类继承对父类静态变量的操作
  11. Day-12: 进程和线程
  12. ES6函数的拓展
  13. Java对正则表达式的支持(二)
  14. 构建高性能服务 Java高性能缓冲设计 vs Disruptor vs LinkedBlockingQueue
  15. 关于单元测试时加载spring-context.xml文件的问题
  16. 行业观察报告:从SAAS困局看行业趋势 ZT
  17. Django学习手册 - 自定义分页函数
  18. Confluence 6 查看所有空间
  19. Spring boot自动设置包依赖,根本不用记,
  20. Python3.5学习十八 Python之Web框架 Django

热门文章

  1. Python 生成器 (generator) &amp; 迭代器 (iterator)
  2. Javascript是如何工作的?
  3. Centos7下安装Relion
  4. POJ 1724 (分层图最短路)
  5. [转]使用IConfigureNamedOptions和ConfigureAll配置命名选项
  6. 计算机组成原理——cache高速缓存存储器
  7. bootstrap 自定义模态窗口
  8. Scala,Java,Python 3种语言编写Spark WordCount示例
  9. Java开发桌面程序学习(六)——拖动文件获得文件路径
  10. python基础(29):网络编程(软件开发架构、网络基础、套接字初使用)