C. Kyoya and Colored Balls

Time Limit: 2000ms
Memory Limit: 262144KB

64-bit integer IO format: %I64d      Java class name: (Any)

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, modulo 1 000 000 007.

 

Sample Input

Input
3
2
2
1
Output
3
Input
4
1
2
3
4
Output
1680

Hint

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

1 2 1 2 3
1 1 2 2 3
2 1 1 2 3 题目大意为,有n种球,编号分别为1234....n,每种球有ci个,问有几种取法,能把盒子里的球拿完,要求是每次取完一种球前,编号比他小的球都取完。 思路:从小往大排列,首先一开始只有一个格子可以放,放入(c1-1)个一号球,并把最后一个一号球放最后,这样一共有(c1+1)个格子,然后在这么多格子里放入(c2-1)个二号球,并把最后一个二号球放在最后,这样一直到最后。
对于 n个格子里放m个球,打个表球行。n个格子放m个球 放的种类就是(n-1个格子放0,1,2,3,4,....mg个球)求和, 推倒一下很容易得到(n个格子放m个球)=(n-1格子放m个球)+(n格子放m-1个球)。这就是推导公式。 代码:
#include <stdio.h>
#include <iostream>
#include <string.h>
#define maxx 1010 using namespace std; int main(){
long long s[maxx][maxx]={};
int t;
int a=;
int q;
long long ans=;
for(int i=;i<maxx;i++)
s[i][]=;
for(int i=;i<maxx;i++)
for(int j=;j<maxx;j++)
s[i][j]=(s[i][j-]+s[i-][j])%;
cin>>t;
for(int i=;i<t;i++){
cin>>q;
ans=(ans*s[a][q-])%;
a+=q;
}
cout<<ans; }

Codeforces554 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. Kyoya and Colored Balls(组合数)

    Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

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

  4. 554C - Kyoya and Colored Balls

    554C - Kyoya and Colored Balls 思路:组合数,用乘法逆元求. 代码: #include<bits/stdc++.h> using namespace std; ...

  5. codeforces 553A A. Kyoya and Colored Balls(组合数学+dp)

    题目链接: A. Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes i ...

  6. CF-weekly4 F. Kyoya and Colored Balls

    https://codeforces.com/gym/253910/problem/F F. Kyoya and Colored Balls time limit per test 2 seconds ...

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

    题目描述: Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  8. codeforces 553A . Kyoya and Colored Balls 组合数学

    Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are ...

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

随机推荐

  1. Ubuntu 登录锐捷 网卡被禁用 网口灯不亮解决

    cd rjsupplicantchmod +x rjsupplicant.sh sudo ./rjsupplicant.sh -u username-p password -d 1 sudo serv ...

  2. ACM-ICPC代码模板

    是不是感觉手中的模板都各有缺陷? 要找到好的模板就要集百家之所长, 我在这里贡献出我的代码模板丰富大家的积累. 我的模板能较好的与常见的模板形成互补. 赶快收藏吧,否则以后找不到就不好啦! 另外,想成 ...

  3. iOS中滤镜处理及相关内存泄漏问题的解决

    最近工作之余在做一个美图秀秀的仿品 做到滤镜这块的时候  自己就参考了网上几位博主(名字忘了记,非常抱歉)的博客,但是发现跟着他们的demo做的滤镜处理,都会有很严重的内存泄漏,于是就自己按照大体的思 ...

  4. 八皇后问题_Qt_界面程序实现

    //核心代码如下 //Queen--放置皇后 #include "queue.h" queue::queue() { *; ; this->board = new bool[ ...

  5. 安装SQL SERVER 2005出现“sql2005 执行安装向导期间出错 ”

    安装sql server 2005时出现“sql2005 执行安装向导期间出错”的提示,百度找了一下,发现原来是解压时候才安装了CD1的,还有CD2的没解压安装,解压CD2安装即可

  6. AngularJs ng-route路由详解

    本篇基于ng-route来讲下路由的使用...其实主要是 $routeProvider 搭配 ng-view 实现. ng-view的实现原理,基本就是根据路由的切换,动态编译html模板. 更多内容 ...

  7. EXT.NET 使用总结(1)

    前言 从系统改版到现在,将近半年的时间,原本陌生的Ext.NET的UI框架,也慢慢的熟悉了.总的来说,这个UI框架还是很优秀的,但是也没有100%完美的产品(老系统使用easy ui其实也挺好的).趁 ...

  8. JavaOO面向对象中的注意点

    1.JavaOO宗旨思想: ★万物皆对象,对象因关注而产生★ ☆类是对象的抽取,对象是类的实例☆ 2.JavaOO的三大特征: 封装.继承.多态  (第四大特征 抽象 现还有争议) 3.属性与行为: ...

  9. php调试

    转自:http://www.cnblogs.com/gidot/p/4307709.html

  10. 摸索探寻之Mac OS 使用及快捷键

    刚发现的一个介绍Mac OS入门的帖子,新入手Mac的同学可以看看http://www.cnblogs.com/chijianqiang/archive/2011/08/03/2126593.html ...