码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #309 (Div. 2)

时间:2015-06-29 13:16:22      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:

A. Kyoya and Colored Balls

一个背包有K种颜色一共N个球,颜色分别为1,2,3...K,颜色相同的球是不区别的。现在从背包里一个一个拿球直到所有球拿光,在拿光第I+1种颜色球之前一定要拿光第I种颜色的球,求有多少种拿法

如 果只有一种颜色的球,拿的方法只有一种。如果有两种,留下一个颜色为2的放在最后一个,剩下的N1个颜色1和N2-1个颜色2的可以随意摆,方法数为 1*\(N1+N2-1 \choose N2-1\);如果有三种相当于先排好颜色为1,2的,然后剩下N3-1个颜色为3的插空

技术分享
#include <cstdio>
#include <cstring>

typedef long long ll;
const int N = 2000;
const ll MOD = 1e9+7;
ll C[N][N];
int num[N];

int main() {
    C[0][0] = 1;
    for (int i = 1; i < N; i++) {
        C[i][0] = 1;
        for (int j = 1; j <= i; j++) {
            C[i][j] = C[i-1][j] + C[i-1][j-1];
            while (C[i][j] >= MOD) {
                C[i][j] -= MOD;
            }
        }
    }
    int k;
    scanf("%d", &k);
    for (int i = 1; i <= k; i++) {
        scanf("%d", &num[i]);
    }
    ll ans = 1;
    ll cnt = num[1];
    for (int i = 2; i <= k; i++) {
        ans = (ans*C[cnt+num[i]-1][num[i]-1])%MOD;
        cnt += num[i];
    }
    printf("%lld\n", ans);
    return 0;
}
View Code
 
B. Kyoya and Permutation

Codeforces Round #309 (Div. 2)

标签:

原文地址:http://www.cnblogs.com/cheater/p/4607078.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!