Kyoya and Colored Balls(组合数)
2 seconds
256 megabytes
standard input
standard output
Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color i before drawing the last ball of color i + 1 for all i from 1 to k - 1. Now he wonders how many different ways this can happen.
The first line of input will have one integer k (1 ≤ k ≤ 1000) the number of colors.
Then, k lines will follow. The i-th line will contain ci, the number of balls of the i-th color (1 ≤ ci ≤ 1000).
The total number of balls doesn't exceed 1000.
A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1 000 000 007.
3 2 2 1
3
4 1 2 3 4
1680
In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are:
1 2 1 2 3 1 1 2 2 3 2 1 1 2 3
题意:
有k种颜色,每种颜色对应a[i]个球,球的总数不超过1000
要求第i种颜色的最后一个球,其后面接着的必须是第i+1种颜色的球
问一共有多少种排法
对于每一种颜色的求有当前所剩的总位数sum,当前颜色个数a
C(sum - 1, a - 1);
乘上所有的情况就好了;
另外组合数要打表求出;
C[i][j] = C[i - 1][j] + C[i - 1][j - 1];杨辉三角的求法;
代码:
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#define LL __int64
using namespace std;
const int MAXN = ;
const LL MOD = ;
int a[MAXN];
LL C[MAXN][MAXN];
void db(){
C[][] = ;
C[][] = ; C[][] = ;
for(int i = ; i < MAXN; i++){
C[i][] = C[i][i] = ;
for(int j = ; j < i; j++){
C[i][j] = C[i - ][j] + C[i - ][j - ];
C[i][j] %= MOD;
}
}
}
int main(){
int k;
db();
while(~scanf("%d", &k)){
LL sum = ;
for(int i = ; i <= k; i++){
scanf("%d", a + i);
sum += a[i];
}
LL ans = ;
for(int i = k; i >= ; i--){
ans *= C[sum - ][a[i] - ];
ans %= MOD;
// printf("%d %d %d\n", sum - 1, a[i] - 1, C[sum - 1][a[i] - 1]);
sum -= a[i];
}
printf("%I64d\n", ans);
}
return ;
}
Kyoya and Colored Balls(组合数)的更多相关文章
- 554C - Kyoya and Colored Balls
554C - Kyoya and Colored Balls 思路:组合数,用乘法逆元求. 代码: #include<bits/stdc++.h> using namespace std; ...
- Codeforces A. Kyoya and Colored Balls(分步组合)
题目描述: Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- Codeforces554 C Kyoya and Colored Balls
C. Kyoya and Colored Balls Time Limit: 2000ms Memory Limit: 262144KB 64-bit integer IO format: %I64d ...
- Codeforces Round #309 (Div. 2) C. Kyoya and Colored Balls 排列组合
C. Kyoya and Colored Balls Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...
- C. Kyoya and Colored Balls(Codeforces Round #309 (Div. 2))
C. Kyoya and Colored Balls Kyoya Ootori has a bag with n colored balls that are colored with k diffe ...
- codeforces 553A A. Kyoya and Colored Balls(组合数学+dp)
题目链接: A. Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes i ...
- CF-weekly4 F. Kyoya and Colored Balls
https://codeforces.com/gym/253910/problem/F F. Kyoya and Colored Balls time limit per test 2 seconds ...
- Codeforces Round #309 (Div. 2) C. Kyoya and Colored Balls
Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are ...
- Codeforces554C:Kyoya and Colored Balls(组合数学+费马小定理)
Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are ...
随机推荐
- 详述.NET里class和struct的异同
结构与类共享几乎所有相同的语法,但结构比类受到的限制更多:尽管结构的静态字段可以初始化,结构实例字段声明还是不能使用初始值设定项. 结构不能声明默认构造函数(没有参数的构造函数)或析构函数. 结构的副 ...
- Microsoft Visual C++ 不支持long long
Microsoft Visual C++ 不支持long long 在C/C++中,64为整型一直是一种没有确定规范的数据类型.现今主流的编译器中,对64为整型的支持也是标准不一,形态各异.一般来说, ...
- Jquery on() 动态绑定事件
之前就一直受这个问题的困扰,在jQuery1.7版本之后添加了on方法,之前就了解过,其优越性高于live(),bind(),delegate()等方法,在此之前项目中想用这个来测试结果发现,居然动态 ...
- NFinal学习笔记 02—NFinalBuild
在学习NFinal的过程中发现在线.net编译器Web版—— NFinalBuild 什么是NFinalBuild呢?它就是帮助我们简单又快速的更新我们网站的一种编译器,我们不用再只为了更新.net网 ...
- Volley的三种基本用法StringRequest的Get和post用法以及JsonObjectRequest
首先做出整个应用的全局请求队列 package com.qg.lizhanqi.myvolleydemo; import android.app.Application; import com.and ...
- PHP学习笔记十八【构造函数】
<?php class Person{ public $name; public $age; //定义构造函数 function 空格__construct 构造方法没有返回值,对象自动调用 p ...
- iOS nav加角标
写一个类别加上就可以啦 #import "UIBarButtonItem+Badge.h" #import "BadgeView.h" #import < ...
- 关于Struts2的类型转换详解
详细出处参考:http://www.jb51.net/article/35465.htm 一.类型转换的意义 对于一个智能的MVC框架而言,不可避免的需要实现类型转换.因为B/S(浏览器/服务器)结构 ...
- HDU 5735 - Born Slippy
题意: 一棵 n 个节点的根树,i 节点权重 wi 对每一个节点s,找到这样一个长 m 的标号序列 v : 1. vi是vi-1 的祖先 2. f[s] = w[vi] + ∑(i=2, m) (w[ ...
- uva 12100 Printer Queue
The only printer in the computer science students' union is experiencing an extremely heavy workload ...