Kyoya and Colored Balls
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.
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
-------------------------------editorial---------------------------------------
this problem can easily implement if we do some special considerations
initially ans=1;
lets decide answer for using one number at a time
let us take biggest element initially one of the biggest element must be at the last of the sequence ,soo after fixing one of the bigest number at the last position , now we have pos-1 positions remain and occurance of bigest nu-1 no of biggest number remain so we can arrange those number at any remaining positions soo
ans*=(pos-1) C(no of remaining biggest numger)
after fixing all biggest number number of remaining positions are total positions - number of occurance of biggest number
now we set answer for second biggest number in the same manar and multiply with the privious ansewer
------------------------------------------code--------------------------------
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef long int li;
typedef unsigned long long int ulli;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define test() int t, cin>>t,while(t--)
lli combination()
{
for(int i = 0; i < 1000; i++) {
comb[i][0] = 1;
for(int j = 1; j <= i; j++)
comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % mod;
}
}
using namespace std;
int main()
{
int n;
combination();
cin>>n;
vector<int> v;
int tot=0;
for(int i=0;i<n;i++)
{
int d;
cin>>d;
v.push_back(d);
tot+=v[i];
}
lli ans=1;
for(int i=n-1;i>=0;i--)
{
int count=v[i];
ans=(ans*comb[tot-1][count-1])%mod;
tot-=count;
}
cout<<ans<<endl;
}