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/contest/554/problem/C
Description
Input
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.
Output
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.
Sample Input
3
2
2
1
Sample Output
3
HINT
题意
一个袋子里有n种颜色,然后分别告诉你,某个颜色最后拿出来的编号是什么,然后要求这些颜色的最后一个球拿出来的顺序和给定的顺序一样
问你一共有多少种拿法
题解:
排列组合,答案是PI(C(a[i]-1,sum-1)
这个排列组合是我凭感觉猜的,然后试了试,发现是对的……
然后就A了,唔,用数学解释的话,就倒着理解,就比较好懂,倒着放球
(其实这是一道数学题
代码
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 2000001
#define mod 1000000007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** ll fac[maxn];
ll qpow(ll a,ll b)
{
ll ans=;a%=mod;
for(ll i=b;i;i>>=,a=a*a%mod)
if(i&)ans=ans*a%mod;
return ans;
}
ll C(ll n,ll m)
{
if(m>n||m<)return ;
ll s1=fac[n],s2=fac[n-m]*fac[m]%mod;
return s1*qpow(s2,mod-)%mod;
}
int n;
int a[];
int sum;
int main()
{
fac[]=; for(int i=;i<maxn;i++)
fac[i]=fac[i-]*i%mod;
int n=read();
for(int i=;i<n;i++)
a[i]=read();
ll ans=;
sum=a[];
for(int i=;i<n;i++)
{
sum+=a[i];
ans=(ans*C(sum-,a[i]-))%mod;
}
cout<<ans<<endl;
}
Codeforces Round #309 (Div. 2) 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 different colors. The colors are ...
- 找规律 Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks
题目传送门 /* 找规律,水 */ #include <cstdio> #include <iostream> #include <algorithm> #incl ...
- Codeforces Round #309 (Div. 1) B. Kyoya and Permutation 构造
B. Kyoya and Permutation Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...
- Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks 字符串水题
A. Kyoya and Photobooks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- Codeforces Round #309 (Div. 2) -D. Kyoya and Permutation
Kyoya and Permutation 这题想了好久才写出来,没看题解写出来的感觉真的好爽啊!!! 题目大意:题意我看了好久才懂,就是给你一个序列,比如[4, 1, 6, 2, 5, 3],第一个 ...
- Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks【*组合数学】
A. Kyoya and Photobooks time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Codeforces Round #167 (Div. 2) D. Dima and Two Sequences 排列组合
题目链接: http://codeforces.com/problemset/problem/272/D D. Dima and Two Sequences time limit per test2 ...
- A. Kyoya and Colored Balls_排列组合,组合数
Codeforces Round #309 (Div. 1) A. Kyoya and Colored Balls time limit per test 2 seconds memory limit ...
- 贪心 Codeforces Round #309 (Div. 2) B. Ohana Cleans Up
题目传送门 /* 题意:某几列的数字翻转,使得某些行全为1,求出最多能有几行 想了好久都没有思路,看了代码才知道不用蠢办法,匹配初始相同的行最多能有几对就好了,不必翻转 */ #include < ...
随机推荐
- 高手就用Chrome不安全模式
背景:最近玩CSS3和HTML玩得不可开交. 既然要用浏览器的话,就最好在浏览器中设置一个主页,以前徒简洁就一直用百度的搜索页做主页,但是现在百度邪恶的各种广告实在让我恶心,而且一些文献资料中国网站上 ...
- NGUI-制作位图字体以及图文混排
制作字体过程 首先得下载一个位图制作工具Bitmap font generator,可以点击这里下载 1.新建txt文件,输入字体里面包含的文字 2.保存为utf-8格式:点击文件另存为,选择编码格式 ...
- 认识Agile,Scrum和DevOps
If everything's under control you are going too slow. 当今的开发,要求faster and faster.所以我们要Agile,become Ag ...
- CenotOS ip a
- 深入浅出谈存储之NAS是什么
深入浅出谈存储之NAS是什么 2012年02月17日16:42 来源:新浪博客 作者:林沛满 编辑:曾智强 查看全文 赞(0)评论(0) 分享 标签: NAS , 企业NAS , 存储系统 [IT16 ...
- C++builder XE 安装控件 及输出路径
C++builder XE 安装控件 与cb6不一样了,和delphi可以共用一个包. 启动RAD Studio.打开包文件. Project>Options>Delphi Compile ...
- css斜线
斜线 .demo{ display: inline-block; width: 400px; height: 100px; resize: both; overflow: auto; margin-t ...
- POJ3345
http://poj.org/problem?id=3345 大意: 大意是说现在有n个城市来给你投票,你需要至少拿到m个城市的赞成票.想要获得第i个城市的赞成需要花费w[i],有个条件就是某些城市是 ...
- WinForm控件使用文章收藏整理完成
对C# WinForm开发系列收集的控件使用方面进行整理, 加入了一些文章, 不断补充充实, 完善这方面. 基础 - 常用控件 C# WinForm开发系列 - CheckBox/Button/Lab ...
- CSS学习篇核心之——盒子模型
概述 关于CSS的一些基础知识我们在前面文章中已经有所了解,这篇文章我们主要来学习下CSS中的核心知识盒子模型的知识. 盒子模型 元素框的最内部分是实际的内容(element),直接包围内容的是内边距 ...