C. Kyoya and Colored Balls

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/554/problem/C

Description

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

3
2
2
1

Sample Output

3

HINT

题意

一个袋子里有n种颜色,然后分别告诉你,某个颜色最后拿出来的编号是什么,然后要求这些颜色的最后一个球拿出来的顺序和给定的顺序一样

问你一共有多少种拿法

题解:

排列组合,答案是PI(C(a[i]-1,sum-1)

这个排列组合是我凭感觉猜的,然后试了试,发现是对的……

然后就A了,唔,用数学解释的话,就倒着理解,就比较好懂,倒着放球

(其实这是一道数学题

代码

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 2000001
#define mod 1000000007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** ll fac[maxn];
ll qpow(ll a,ll b)
{
ll ans=;a%=mod;
for(ll i=b;i;i>>=,a=a*a%mod)
if(i&)ans=ans*a%mod;
return ans;
}
ll C(ll n,ll m)
{
if(m>n||m<)return ;
ll s1=fac[n],s2=fac[n-m]*fac[m]%mod;
return s1*qpow(s2,mod-)%mod;
}
int n;
int a[];
int sum;
int main()
{
fac[]=; for(int i=;i<maxn;i++)
fac[i]=fac[i-]*i%mod;
int n=read();
for(int i=;i<n;i++)
a[i]=read();
ll ans=;
sum=a[];
for(int i=;i<n;i++)
{
sum+=a[i];
ans=(ans*C(sum-,a[i]-))%mod;
}
cout<<ans<<endl;
}

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

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

  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 #167 (Div. 2) D. Dima and Two Sequences 排列组合

    题目链接: http://codeforces.com/problemset/problem/272/D D. Dima and Two Sequences time limit per test2 ...

  8. A. Kyoya and Colored Balls_排列组合,组合数

    Codeforces Round #309 (Div. 1) A. Kyoya and Colored Balls time limit per test 2 seconds memory limit ...

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

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

随机推荐

  1. php生成百度新闻源xml

    <?php /* http://baike.baidu.com/view/125547.htm#2 百度网新闻开放协议 */ mysql_connect($CFG['db_host'] ,$CF ...

  2. mac配置appium进行自动化测试

    先去brew.sh这个网站,拷贝最新的下载安装命令,黏贴到终端里,回车,按提示下载安装. 安装完毕后,运行brewupdate 看看是否有更新,然后输入brew ios-webkit-debug-pr ...

  3. NewtonPrincipia_物体的运动_求向心力

    NewtonPrincipia_物体的运动_求向心力 让我们看一下十七世纪的被苹果砸中的艾萨克,是怎样推导出向心力公式的 在现在的观点看来,其中涉及到的很多没有符号表示的微分量.下面的内容只是叙述了推 ...

  4. Leetcode 225 Implement Stack using Queues

    Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...

  5. easyui dialog遮罩层

    当dialog在一个iframe里时,此dialog的遮罩层也会只覆盖这个iframe,要想覆盖整个页面,就把dialog写到最外层的父页面中去,此时dialog的遮罩层会自动覆盖整个页面,若需要从子 ...

  6. 【转】Eclipse去除js(JavaScript)验证错误

    这篇文章主要是对Eclipse去除js(JavaScript)验证错误进行了介绍.在Eclipse中,js文件常常会报错.可以通过如下几个步骤解决 第一步:去除eclipse的JS验证:将window ...

  7. Java Applet and ServiceLoader

    http://stackoverflow.com/questions/14062813/java-applet-and-serviceloader

  8. 如何通过写一个chrome扩展启动本地程序

    @(编程) [toc] 本文介绍如何利用Chrome 的插件, 从我们的一个网站中启动一个我们的本地程序.本文的环境是windows10,本文的例子是通过点击网页上的一个button,调用本地的wor ...

  9. 将UIImage保存成JPG或PNG格式存储在本地

    -(void)pngAndJpg:(UIImage*)image{ NSString *pngPath = [NSHomeDirectory() stringByAppendingPathCompon ...

  10. 前端MVC学习总结(三)——AngularJS服务、路由、内置API、jQueryLite

    一.服务 AngularJS功能最基本的组件之一是服务(Service).服务为你的应用提供基于任务的功能.服务可以被视为重复使用的执行一个或多个相关任务的代码块. AngularJS服务是单例对象, ...