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 ...
随机推荐
- 如果将彩色图像和灰度图像一起放进 CNN 中去,会是什么结果?
如果将彩色图像和灰度图像一起放进 CNN 中去,会是什么结果? 今天,坑爹的实验,我处理 SUN397 的时候,忘记去掉灰度图了,结果,利用微调后的 model 提取 feature,悲剧的发现,无论 ...
- Understanding postgresql.conf : log*
After loooong pause, adding next (well, second) post to the “series“. This time, I'd like to describ ...
- How to drop a PostgreSQL database if there are active connections to it?
1.PostgreSQL 9.1 and below: SELECT pg_terminate_backend(pg_stat_activity.procpid) FROM pg_stat_activ ...
- 关于mybatis组合查询的分析
mybatis 查询思路 第一种思路: 1:先查询,编写查询语句: 2:查询出结果后,将ResultMap 进行拆分, 组合成想要的模型: 这种思路是将联合查询语句组合成一个ResultMap; &l ...
- MVC View中获取Url参数的值
如果url是 /home/index?id=3 直接Request就ok. Razor方法 @Html.ViewContext.RouteData.Values["id"] @Re ...
- 螺旋矩阵 noip2014普及组
本题可以直接模拟填数字,也可以直接计算结果. 代码一:(这个代码,缺陷在于数组太大,浪费内存啊.另外,循环次数也不少.总之,时间空间的消耗都不小.) /*======================= ...
- BNUOJ 1006 Primary Arithmetic
Primary Arithmetic 来源:BNUOJ 1006http://www.bnuoj.com/v3/problem_show.php?pid=1006 当你在小学学习算数的时候,老师会教你 ...
- js正则及常用方法函数总结
正则表达式作为一种匹配处理字符串的利器在很多语言中都得到了广泛实现和应用,web开发本质上是处理字符串(服务端接受请求处理后拼接字符串作为响应,这在早期的CGI编程中最明显,然后客户端解析字符串进行渲 ...
- Win7系统上配置使用Intellij Idea 13的SVN插件
Win7系统上配置使用Intellij Idea 13的SVN插件 http://blog.csdn.net/jeepxiaozi/article/details/39856081
- postman使用教程
最近很多朋友在问postman的使用方法,现我经过整理,分享给大家. Postman 是一个很强大的 API调试.Http请求的工具,当你还准备拿着记事本傻傻的去写 Form 表单的时候,你来试试 P ...