codeforces 553 A Kyoya and Colored Balls
这个题。比赛的时候一直在往dp的方向想,可是总有一个组合数学的部分没办法求,
纯粹组合数学撸,也想不到办法……
事实上,非常显然。。
从后往前推,把第k种颜色放在最后一个,剩下的k球。还有C(剩余的位置,k球的总数目-1)种放法
然后讨论第k-1种。。。推下去就好了
可是当时没想到……
这里要求组合数。因为比較大。用乘法逆元。。。
当然直接套lucas也是能够的。
。。。
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
#include<iostream>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
ll qpow(ll a,ll b)
{
ll ans=1,c=a;
while(b)
{
if(b&1)
ans=ans*c%mod;
b>>=1;
c=c*c%mod;
}
return ans;
}
ll fac[1000010];
ll work(int a,int b)
{
return fac[a]*qpow(fac[b]*fac[a-b]%mod,mod-2)%mod;
}
int a[1010];
int main()
{
fac[0]=1;
for(int i=1;i<=1000000;i++)
fac[i]=fac[i-1]*i%mod;
int n;
cin>>n;
int sum=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
sum+=a[i];
}
ll ans=1;
for(int i=n-1;i>-1;i--)
{
ans=ans*work(sum-1,a[i]-1)%mod;
sum-=a[i];
}
cout<<ans;
}
codeforces 553 A Kyoya and Colored Balls的更多相关文章
- 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 ...
- 【47.95%】【codeforces 554C】Kyoya and Colored Balls
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard 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 ...
- Codeforces A. Kyoya and Colored Balls(分步组合)
题目描述: Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- 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 ...
- 554C - Kyoya and Colored Balls
554C - Kyoya and Colored Balls 思路:组合数,用乘法逆元求. 代码: #include<bits/stdc++.h> using namespace std; ...
随机推荐
- js的弹性运动
弹性: 速度+=(目标点-当前值)/系数://系数大概可以选择6,7,8 速度*=摩擦系数://系数可以选择0.7,0.75,0.8 缓冲: 速度=(目标点-当前值)/系数: 速度取整:
- Web框架之Django_08 重要组件(form组件、cookie和session组件)
摘要: form组件 cookie组件 session组件 一.form组件 form介绍我们之前在html页面中利用form表单向后端提交数据时候,都需要对用户的输入进行校验,比如校验用户是否输入正 ...
- Python多版本共存安装
Python的安装 进入Python官方网站:www.python.org下载系统对应的Python版本 按照提示步奏安装,安装路径选择自定义,方便查找 安装完成后,按win+R键,输入cmd进入cm ...
- JavaScript正则表达式-相关的String对象方法
match()方法 match(regExp); 使用指定的正则表达式来搜索字符串. 如果找到匹配字符串返回一个数组,否则返回null. 返回的数组包含两个属性:index和input. index是 ...
- [android开发篇]项目目录结构
- ASP.NET上传大文件404报错
报错信息: Failed to load resource: the server responded with a status of 404 (Not Found) 尝试1: 仅修改Web.con ...
- 有关php启动时候报错信息
1 : An another FPM instance seems to already listen on /tmp/php-cgi.sock有关/tem/php-cgi.sock问题查看进程可以或 ...
- BZOJ 1933 [Shoi2007]Bookcase 书柜的尺寸 ——动态规划
状态设计的方法很巧妙,六个值 h1,h2,h3,t1,t2,t3,我们发现t1,t2,t3可以通过前缀和优化掉一维. 然后考虑把h留下还是t留下,如果留下h显然t是会发生改变的,一个int存不下. 如 ...
- Spring-IOC源码解读2.2-BeanDefinition的载入和解析过程
1. 对IOC容器来说这个载入过程就像是相当于把BeanDefinition定义的信息转化成Spring内部表示的数据结构.容器对bean的管理和依赖注入过程都是通过对其持有的BeanDefiniti ...
- 前端ui框架---ant 蚂蚁金服开源
蚂蚁金服和饿了么好像不错 饿了么官网:http://element.eleme.io/#/zh-CN饿了么github:http://github.com/elemefe 蚂蚁金服 https:// ...