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

时间:2021-02-10 11:09:36

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;
}