Given a k to indicate the kind of color from 1 to K
Then the next K-line, a number per line, represents the color of the ball how many
These balls are placed in a bag and then taken out in turn. The last ball of color I must be in front of the last ball of color i+1, 1<=i<=k-1
We start with a small judgment,
When k=2,
When K=3, the a[2]-1 ball can be inserted in each of the a[0]+a[1 in each arrangement already arranged, because it is already lined up (that is, the position cannot be changed), so a[0]+a[1] ball can be regarded as a ball of the same color
So this kind of random insertion is equivalent to how many different permutations. It is
This is the result of the random interpolation in each arrangement, there is a total arrangement, when k=3, the total is the two formulas multiply
1#include <stdio.h>2#include <string.h>3#include <stdlib.h>4#include <algorithm>5#include <iostream>6#include <queue>7#include <stack>8#include <vector>9#include <map>Ten#include <Set> One#include <string> A#include <math.h> - using namespacestd; - #pragmaWarning (disable:4996) thetypedefLong LongLL; - Const intINF =1<< -; - /* - + */ - Const intMOD =1000000007; + inta[ ++Ten]; ALL fact[1000001]; at - ll Mypow (ll A, ll b) - { -LL ret =1; - while(b) - { in if(B &1) -RET = ret * A%MOD; toA = a * a%MOD; +b >>=1; - } the returnret; * } $LL C (intNintm)Panax Notoginseng { - if(M > N | | m <0)return 0; theLL a = Fact[n], b = fact[n-m] * Fact[m]%MOD; + returnA * MYPOW (b, MOD-2)% MOD;//dividing by one number equals multiplying the inverse of the number, and then in the case of the MoD A } the + intMain () - { $fact[0] =1; $ for(inti =1; I <1000001; ++i) -Fact[i] = fact[i-1] * I%MOD; - intN; thescanf"%d", &n); - for(inti =0; I < n; ++i)Wuyiscanf"%d", &a[i]); the intsum = a[0]; -LL ans =1; Wu for(inti =1; I < n; ++i) - { AboutSum + =A[i]; $Ans = ans * C (Sum-1, Sum-a[i]-1) %MOD; - } -printf"%i64d\n", ans); - return 0; A}
Codeforces round#309 C Kyoya and colored Balls