嘛,一直以来蒟蒻都没怎么打过CF……现在还是蓝名狗……今天跟着zyf打了一场virtual,果断一题滚粗【Codeforces】【#295】【Div.1】

Kyoya and Colored Balls

  签到题,从前往后考虑,第$i$种球的最后一个一定要放在当前序列的最后一个位置,剩下的$a[i]-1$个可以在前面随便放……所以$ans=\prod_{i=2}^n \binom{s[i]-1}{a[i]-1} $

 1 //Codeforces #309 A
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<iostream>
 6 #include<algorithm>
 7 #define rep(i,n) for(int i=0;i<n;++i)
 8 #define F(i,j,n) for(int i=j;i<=n;++i)
 9 #define D(i,j,n) for(int i=j;i>=n;--i)
10 #define pb push_back
11 using namespace std;
12 typedef long long LL;
13 inline int getint(){
14     int r=1,v=0; char ch=getchar();
15     for(;!isdigit(ch);ch=getchar()) if (ch=='-') r=-1;
16     for(; isdigit(ch);ch=getchar()) v=v*10-'0'+ch;
17     return r*v;
18 }
19 const int N=100010,P=1000000007;
20 /*******************template********************/
21 LL n,a[N],s[N];
22 LL sum,ans=1,fac[N],inv[N];
23 LL Pow(LL a,int b){
24     LL r=1;
25     for(;b;b>>=1,a=a*a%P) if (b&1) r=r*a%P;
26     return r;
27 }
28 LL C(int n,int m){ return fac[n]*inv[m]%P*inv[n-m]%P;}
29 int main(){
30 #ifndef ONLINE_JUDGE
31     freopen("A.in","r",stdin);
32     freopen("A.out","w",stdout);
33 #endif
34     n=getint();
35     fac[0]=fac[1]=1;
36     F(i,1,1000) fac[i]=fac[i-1]*i%P;
37     inv[1000]=Pow(fac[1000],P-2); inv[0]=1;
38     D(i,999,1) inv[i]=inv[i+1]*(i+1)%P;
39 
40     F(i,1,n) a[i]=getint(),s[i]=(s[i-1]+a[i])%P;
41     ans=1;
42     F(i,2,n) ans=ans*C(s[i]-1,a[i]-1)%P;
43     cout <<ans<<endl;
44     return 0;
45 }
View Code

相关文章: