codeforces 553A - Kyoya and Colored Balls (组合计数 + dp)
题目链接:https://codeforces.com/problemset/problem/553/Asuoy
令 \(dp[i]\) 表示前 k 个颜色的答案
当前颜色,肯定有一个球在最后,将剩余的\(c[i]-1\)个球插到前面所有球中的方案数是
\[{tot + c[i] - 1 \choose c[i]-1}
\]
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;
const int maxn = 1010;
const int M = 1000000007;
int k;
int a[maxn],dp[maxn];
int c[maxn][maxn];
void init(){
c[0][0] = 1;
for(int i=1;i<=1000;++i){
c[i][0] = 1;
for(int j=1;j<=1000;++j){
c[i][j] = (c[i-1][j-1] + c[i-1][j]) % M;
}
}
}
ll read(){ ll s=0,f=1; char ch=getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9'){ s=s*10+ch-'0'; ch=getchar(); } return s*f; }
int main(){
init();
k = read();
for(int i=1;i<=k;++i) a[i] = read();
int ans = 0,sum = 0;
dp[0] = 1;
for(int i=1;i<=k;++i){
dp[i] = 1ll * dp[i-1] * c[sum+a[i]-1][a[i]-1] % M;
sum = (sum + a[i]) % M;
}
printf("%d\n",dp[k]);
return 0;
}