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 ...
随机推荐
- 导致flash屏幕重绘的几种方式及避免重绘的方法
导致屏幕重绘的几种原因: 1.最常见的是情况就是舞台上的可视组件在形状.位置.状态(alpha, scale…)发生改变的时候会触发Flash Player 的重绘. 2.当一个DisplayObje ...
- 再一次强调,ORACLE外键必须加索引
外键加索引是常识,必须牢记.本来不想写这样的简单案例.可是连续遇到好几起外键不加索引导致性能问题,所以还是写一下. 一个兄弟问我 delete from Sa_Sales_Comm_Detail s ...
- Spark1.0.0 分布式环境搭建
软件版本号例如以下: Hostname IP Hadoop版本号 Hadoop 功能 系统 master 192.168.119.128 1.1.2 namenode jdk1.6+hadoop+sc ...
- 用户向导页面实现左右滑动的ImageSwitcher
当你第一次打开app时刻,通常有使用向导现在演示APK基本功能和用法,该向导是非常重要的,用户可以知道并调整到速度app如何. 实现此使用向导有非常多种方法,比方用ImageSwitcher.View ...
- Qt Assistant 的配置文件qhp--->qch 和qhcp--->qhc详解与生成
Qt Assistant 这个exe文件可以被我们利用到我们自己的程序为我们添加help,是一个文档浏览器,它的搜索功能,还有最主要的就是他可以让客户自己定义自己索要显示的文档,也就是qch文档. ...
- gcc基本用法
GCC基本用法 GCC最基本的用法是: gcc [option] filenames option:编译器所需要的编译选项 filenames:要编译的文件名 gcc编译流程 都以 hello.c 为 ...
- css-盒模型
<!DOCTYPE html>CSS3-盒模型 盒模型属性: width 宽度 height 高度 margin 外边距 border 边框 padding 内边距.test{width: ...
- Asp.net Mvc 请求是如何到达 MvcHandler的——UrlRoutingModule、MvcRouteHandler分析,并造个轮子
这个是转载自:http://www.cnblogs.com/keyindex/archive/2012/08/11/2634005.html(那个比较容易忘记,希望博主不要生气的) 前言 本文假定读者 ...
- asp.net 页面上传文件控件后台代码Request.Files获取不到
今天开发中遇到页面文件上传控件选择了文件,而后台Request.Files.Count取值为0,之前开发中遇到过几次,老是忘掉,今天记下来. html: <input type="fi ...
- Code Complete阅读笔记(二)
2015-03-06 328 Unusual Data Types ——You can carry this technique to extremes,putting all the ...