codeforces 553A . Kyoya and Colored Balls 组合数学
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, modulo1 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 有n个小球,有k种颜色,编号为1~k,每一个小球都被染了一种颜色,
numi表示颜色为i的颜色的球有numi个。
num之和=n
现在问你这n个小球有多少种排列方式,满足第i种颜色的最后一个球后面的球的颜色一定是i+1(1<=i<n) 分析,
先考虑第k种颜色的球,一定有一个第k种颜色的球是放在最后的位置了
#include<cstdio>
#include<cstring> using namespace std; #define ll long long const int maxn=+;
const int mod=1e9+; ll fac[maxn];
ll num[]; inline ll quick_pow(ll x)
{
ll y=mod-;
ll ret=;
while(y){
if(y&){
ret=ret*x%mod;
}
x=x*x%mod;
y>>=;
}
return ret;
} int main()
{
fac[]=;
for(int i=;i<maxn;i++){
fac[i]=(fac[i-]*i)%mod;
}
int k;
scanf("%d",&k);
ll sum=;
for(int i=;i<=k;i++){
scanf("%I64d",&num[i]);
sum+=num[i];
}
ll ans=; for(int i=k;i>=;i--){
ans*=fac[sum-]*quick_pow(((fac[num[i]-]%mod)*(fac[sum-num[i]]%mod))%mod)%mod;
ans%=mod;
sum-=num[i];
}
printf("%I64d\n",ans); return ;
}
codeforces 553A . Kyoya and Colored Balls 组合数学的更多相关文章
- Codeforces A. Kyoya and Colored Balls(分步组合)
题目描述: Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- 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 ...
- Codeforces554C: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(组合数学计算+费马小定理)
题意: 有k种颜色,每种颜色对应a[i]个球,球的总数不超过1000 要求第i种颜色的最后一个球,其后面接着的必须是第i+1种颜色的球 问一共有多少种排法 Sample test(s) input o ...
- 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 ...
- 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 ...
- Codeforces554 C Kyoya and Colored Balls
C. Kyoya and Colored Balls Time Limit: 2000ms Memory Limit: 262144KB 64-bit integer IO format: %I64d ...
- Kyoya and Colored Balls(组合数)
Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
随机推荐
- 【转】BLE_CC2540_初学者入门指导
原文网址:http://www.deyisupport.com/question_answer/wireless_connectivity/bluetooth/f/103/t/61462.aspx 看 ...
- (转) 实时SLAM的未来及与深度学习的比较
首页 视界智尚 算法技术 每日技术 来打我呀 注册 实时SLAM的未来及与深度学习的比较 The Future of Real-Time SLAM and “Deep Learni ...
- NETMON& Message Analyzer
NMCap /network * /capture /file c:\folder\t.chn:1MB NMCap /network * /capture (IPv4.SourceAddress = ...
- dede后台栏目文章问题
栏目下的子栏目文档,并不记在主栏目文档数中,让我一直以为程序错误.
- 网络-CIDR地址分类介绍
CIDR(Classless Inter Domain Routing)改进了传统的IPv4地址分类.传统的IP分类将IP地址直接对应为默认的分类,从而将Internet分割为网络.CIDR在路由表中 ...
- hibernate反向工程 (eclipse和myeclipse)(转)
hibernate反向工程 (eclipse和myeclipse) 如何提取数据库的模式信息,想通过hibernate的反向工具尝试下. 一.myeclipse下hibernate反向工程: 1.选择 ...
- 部署 mozilla-BrowserQuest
1,到GitHub下载代码 https://github.com/mozilla/BrowserQuest 2,安装Node.Js 下载地址 http://nodejs.org/ 直接下载安装版就可 ...
- 一个关于正整数x的约数个数的结论
分析理解:x的每一个约数都是由x的若干个质因数的积构成. 再根据乘法原理,每个质因数Pi的选择可以是0~Ni个,所以上述结论成立.
- C语言的几种取整方法
C语言的几种取整方法 来源:http://blog.sina.com.cn/s/blog_4c0cb1c001013ha9.html 1.直接赋值给整数变量.如: int i = 2.5; 或 i = ...
- javascript 函数式编程
编程范式 编程范式是一个由思考问题以及实现问题愿景的工具组成的框架.很多现代语言都是聚范式(或者说多重范式): 他们支持很多不同的编程范式,比如面向对象,元程序设计,泛函,面向过程,等等. 函数式编程 ...