51nod1453(排列组合)

题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1453

 

题意: 中文题诶~

 

思路: 因为最后一个球总是在编号比他大的球拿完之前拿完, 所以可以先把每种编号的求都拿出一个来, 按照 1, 2, .... n 排列. 然后再把 xi 个 i 号球插入这里的 i 号球之前即可. 然后直接用排列组合计数即可.

 

代码:

 1 #include <iostream>
 2 #define ll long long
 3 using namespace std;
 4 
 5 const int mod = 1e9 + 7;
 6 const int MAXN = 1e3 + 10;
 7 ll a[MAXN], vis[MAXN];
 8 
 9 ll get_pow(ll x, int n){
10     ll ans = 1;
11     while(n){
12         if(n & 1) ans = ans * x % mod;
13         x = x * x % mod;
14         n >>= 1;
15     }
16     return ans;
17 }
18 
19 int main(void){
20     vis[0] = 1;
21     for(ll i = 1; i < MAXN; i++){
22         vis[i] = vis[i - 1] * i % mod;
23     }
24     ll n, x;
25     cin >> n;
26     for(int i = 1; i <= n; i++){
27         cin >> x;
28         a[i] = a[i - 1] + x;
29     }
30     ll cnt1 = 1, cnt2 = 1;
31     for(int i = 1; i <= n; i++){
32         for(ll j = a[i - 1] + 1; j <= a[i] - 1; j++){
33             cnt1 = cnt1 * j % mod;
34         }
35         cnt2 = cnt2 * vis[a[i] - a[i - 1] - 1] % mod;
36     }
37     ll sol = cnt1 * get_pow(cnt2, mod - 2) % mod;
38     cout << sol << endl;
39     return 0;
40 }
View Code

 

posted @ 2017-10-10 22:29  geloutingyu  阅读(240)  评论(0编辑  收藏  举报