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 ...
随机推荐
- 基础总结篇之五:BroadcastReceiver应用详解
問渠那得清如許?為有源頭活水來.南宋.朱熹<觀書有感> 据说程序员是最爱学习的群体,IT男都知道,这个行业日新月异,必须不断地学习新知识,不断地为自己注入新鲜的血液,才能使自己跟上技术的步 ...
- JS~重写alter与confirm,让它们变成fancybox风格
插件与系统命令 对于很多JS弹框插件来说,都提供了alter,confirm等功能,如fancybox,Boxy等插件,今天来介绍一下如何将系统的alter和confirm替换成指定插件的alter和 ...
- 再谈cacheAsBitmap
cacheAsBitmap这个属性很多人都知道,但少有人明白它到底是如何生效的.虽然看名字是转换为位图处理,但用起来的时候感觉却也不过如此.所以,不少人最终选择自己转换Bitmap. 当然,自己转Bi ...
- 关于Latch
Latch是什么 Latch是SQL Server引擎保证内存中的结构的一致性的轻量同步机制.比如索引,数据页和内部结构(比如非叶级索引页).SQL Server使用Buffer Latch保护缓冲池 ...
- html5 video播放不全屏
<video controls="controls" webkit-playsinline src="${page.videoUrl }" type=&q ...
- Android学习笔记--服务(Service)
1.服务概述 1.服务是Android四大组件之一,在使用上可以分为本地服务和远程服务,本地服务是指在不影响用户操作的情况下在后台默默的执行一个耗时操作,例如下载,音频播放等.远程服务是指可以供其他应 ...
- gdal_merge.py
1 gdal_merge.py: 合并(Merge)/镶嵌(Mosaic)工具.要求图像必须是相同坐标系统.具有相同的波段数:可以不同分辨率,可以有重叠区域(后加入图像覆盖先加入的图像). 注意:只能 ...
- C#利用QrCode.Net生成二维码(Qr码)
在网上很多应用都是用二维码来分享网址或者其它的信息.尤其在移动领域,二维码更是有很大的应用场景.因为项目的需要,需要在网站中增加一个生成二维码分析网址的功能,在谷歌大幅度抽筋的情况下无奈使用百度.百度 ...
- Android Canvas设置绘画时重叠部分的处理模式【含效果图】
在Android的PorterDuff.Mode类中列举了他们制定的规则: android.graphics.PorterDuff.Mode.SRC:只绘制源图像 android.graphics.P ...
- Spring的PropertyPlaceholderConfigurer应用
Spring 利用PropertyPlaceholderConfigurer占位符 1. PropertyPlaceholderConfigurer是个bean工厂后置处理器的实现,也就是BeanFa ...