Codeforces554 C Kyoya and Colored Balls
C. Kyoya and Colored Balls
64-bit integer IO format: %I64d Java class name: (Any)
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.
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
3
4
1
2
3
4
1680
Hint
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
1 2 1 2 3
1 1 2 2 3
2 1 1 2 3 题目大意为,有n种球,编号分别为1234....n,每种球有ci个,问有几种取法,能把盒子里的球拿完,要求是每次取完一种球前,编号比他小的球都取完。 思路:从小往大排列,首先一开始只有一个格子可以放,放入(c1-1)个一号球,并把最后一个一号球放最后,这样一共有(c1+1)个格子,然后在这么多格子里放入(c2-1)个二号球,并把最后一个二号球放在最后,这样一直到最后。
对于 n个格子里放m个球,打个表球行。n个格子放m个球 放的种类就是(n-1个格子放0,1,2,3,4,....mg个球)求和, 推倒一下很容易得到(n个格子放m个球)=(n-1格子放m个球)+(n格子放m-1个球)。这就是推导公式。 代码:
#include <stdio.h>
#include <iostream>
#include <string.h>
#define maxx 1010 using namespace std; int main(){
long long s[maxx][maxx]={};
int t;
int a=;
int q;
long long ans=;
for(int i=;i<maxx;i++)
s[i][]=;
for(int i=;i<maxx;i++)
for(int j=;j<maxx;j++)
s[i][j]=(s[i][j-]+s[i-][j])%;
cin>>t;
for(int i=;i<t;i++){
cin>>q;
ans=(ans*s[a][q-])%;
a+=q;
}
cout<<ans; }
Codeforces554 C Kyoya and Colored Balls的更多相关文章
- 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 ...
- Kyoya and Colored Balls(组合数)
Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- 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 ...
- 554C - Kyoya and Colored Balls
554C - Kyoya and Colored Balls 思路:组合数,用乘法逆元求. 代码: #include<bits/stdc++.h> using namespace std; ...
- 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 A. Kyoya and Colored Balls(分步组合)
题目描述: Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- 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 ...
- 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 ...
随机推荐
- MiniProfiler(MiniProfiler.EF6监控调试MVC5和EF6的性能)
git: https://github.com/MiniProfiler 以前开发Webform的时候可以开启trace来跟踪页面事件,这对于诊断程序的性能是有很大的帮助的,起到事半功倍的作用,今天 ...
- this a a mark down test
*** this is title ''' code '''
- 快速上手制作Icon Font
现在在提起Icon Font,已经不是什么新鲜的词汇了,网上已经有很多介绍它的文章,并且很多网站也已经将它用到,本篇主要是将制作Icon Font的整个流程整理一下,并且加入了自己在制作中遇到的问题, ...
- poj1988_Cube Stacking
Cube Stacking Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 24130 Accepted: 8468 Ca ...
- gcc 使用
参数 -E 只进行预处理-S 预处理和编译,生成汇编文件-c 预处理,编译和汇编,生成目标文件-g ...
- NEFU 558 迷宫寻路
题目链接 简单搜索题 #include <cstdio> #include <iostream> #include <cstring> using namespac ...
- LINK1123:failure during conversion to COFF:file invalid or corrupt
参考 http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=20726500&id=4528320 试了微软官方说明:http ...
- ThinkPHP动态版本控制
动态版本控制可以根据时间戳来实现,但是这样的话,每次打开页面都会重新下载加了版本控制的文件,如果你的页面自身打开本来就慢的话, 这样一来,无疑会带来很差的用户体验. 但是如果在每个引用文件后面都手动加 ...
- WordPress安装插件提示输入FTP账户信息
在WP后台安装插件时提示输入FTP账户信息,其实出现这个的问题的原因是Apache/Nginx的执行身份非文件属主身份. 如果你使用的是独立服务器或VPS,WordPress的安装目录为 /home/ ...
- mac 下 用 glfw3 搭建opengl开发环境
mac 下 用 glfw3 搭建opengl开发环境 下载编译 glfw3 Build Setting 里面, Library Search Paths -> 设置好编译 glfw 库的路径 H ...