【47.95%】【codeforces 554C】Kyoya and Colored Balls
time limit per test2 seconds 
memory limit per test256 megabytes 
inputstandard input 
outputstandard 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.
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.
Examples 
input 
3 
2 
2 
1 
output 
3 
input 
4 
1 
2 
3 
4 
output 
1680 
Note 
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
【题目链接】:http://codeforces.com/contest/554/problem/C
【题解】 
 
题意: 
设第i种颜色的球出现的最后一个位置为x 
第i+1种颜色的球出现的最后一个位置为y; 
则严格要求x< y; 
问这样的序列有多少个. 
解法: 
先设所有的颜色的球总共有n个;即n=c1+c2..ck; 
可以从最后一种颜色即颜色为k的球开始考虑; 
现在有n个位置让你摆这第k种颜色的球; 
先考虑第k种颜色的最后一个球要放在哪里? 
肯定是第n个位置. 
因为如果不放在第n个位置,则可能会有其他的球在后面的过程中放在第n个位置,而不管这个球的颜色是什么,它的颜色编号都比k小;这就不满足上上述要求了,因为那种颜色的球最后一次出现的位置肯定比k大.. 
因此把第k种颜色的球的最后一个放在第n个位置; 
接下来第k种颜色的球还有ck-1个;剩下的位置还有n-1个; 
显然剩下的ck-1个球放在哪里都行即C(n-1,ck-1); 
放完第k个球再考虑第k-1种颜色的球. 
还是一样先考虑第k-1种颜色的球的最后出现的球应该放在哪里?? 
肯定是第k中颜色的球放剩下的位置里面的最后一个位置.道理还是一样,如果不先占据那个位置则其他编号比k-1小的球可以放在那里(设为位置x),则编号为k-1的球的最后一次出现的位置肯定小于x,而位置为x的球的编号小于k-1????显然就不合适了。。 
所以先把编号为k-1的球中的一个拿出来放在位置x(即第k中颜色的球放剩下的位置里面的最后一个位置); 
然后剩下n-c[k]-c[k-1]-1个位置,从中选出c[k-1]-1位置放剩下的c[k-1]-1个球…. 
即C(n-c[k]-c[k-1]-1,c[k-1]-1); 
以此类推.. 
 
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int MAXN = 1e3+10;
const int MOD = 1e9+7;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
int k,n = 0;
int c[MAXN][MAXN];
int main()
{
    //freopen("F:\\rush.txt","r",stdin);
    c[0][0] = 1;
    rep1(i,1,1000)
        c[i][i] = 1,c[i][0] = 1;
    rep1(i,1,1000)
        rep1(j,1,1000)
            {
                c[i][j] =c[i-1][j]+c[i-1][j-1];
                if (c[i][j] >= MOD) c[i][j]-=MOD;
            }
    LL ans = 1;
    rei(k);
    rep1(i,1,k)
    {
        int x;
        rei(x);
        n+=x;
        ans = (ans*c[n-1][x-1])%MOD;
    }
    cout << ans << endl;
    return 0;
}
【47.95%】【codeforces 554C】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 ...
 - codeforces 553 A Kyoya and Colored Balls
		
这个题.比赛的时候一直在往dp的方向想,可是总有一个组合数学的部分没办法求, 纯粹组合数学撸,也想不到办法-- 事实上,非常显然.. 从后往前推,把第k种颜色放在最后一个,剩下的k球.还有C(剩余的位 ...
 - 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 ...
 - 554C - Kyoya and Colored Balls
		
554C - Kyoya and Colored Balls 思路:组合数,用乘法逆元求. 代码: #include<bits/stdc++.h> using namespace std; ...
 - Codeforces A. Kyoya and Colored Balls(分步组合)
		
题目描述: Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
 - 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
		
题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...
 - 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 C  Kyoya and Colored Balls
		
给定一个k表示颜色的种类从1到k 然后接下来k行, 每行一个数字, 代表该颜色的球有多少个 这些球都放在一个包中,然后依次拿出. 要求颜色i的最后一个球, 必须要排在颜色i+1的最后一个球前面, ...
 
随机推荐
- 代码生成器实现的Entity,Dao,Service,Controller,JSP神器(含代码附件)
			
package com.flong.codegenerator; import java.sql.Connection; import java.sql.DatabaseMetaData; impor ...
 - 洛谷——U10783 名字被和谐了
			
https://www.luogu.org/problem/show?pid=U10783 题目背景 众所周知,我们称g是a的约数,当且仅当g是正数且a mod g = 0. 众所周知,若g既是a的约 ...
 - Akka边学边写(4)-- MiniRPG
			
前面几篇文章用Akka写了HelloWorld和EchoServer,为了更进一步学习Akka,本文将会实现一个非常小的RPG游戏server:MiniRPG. 游戏逻辑 由于是迷你RPG,所以逻辑非 ...
 - 移动开发js库Zepto.js使用中的一些注意点
			
来自http://chaoskeh.com/blog/some-experience-of-using-zepto.html的参考. 前段时间完成了公司一个产品的 HTML5 触屏版,开发中使用了 Z ...
 - web前端背景介绍
			
Internet:是一个全球性的计算机互联网络,中文名称“因特网”.“国际互联网”.“网际网”等等: Internet提供的服务:http.ftp.Telnet.email.www.bbs等等: 基本 ...
 - ECMALL功能拓扑图以及模式分析
			
ECMALL VS 常规的B2C产品(以ECSHOP做对比)的区别: 1.支持多用户在同一个域名下开店. 2.开店的卖家各自结算,直接收钱.平台只是提供了一个类似传统行业的摊位.平台不过手金钱 3 ...
 - Cocos2d 游戏状态机
			
加cocos2d 是标题党. 事实上跟cocos2d无关. 1.游戏背景介绍 比方有这么一个"记忆"类的比赛游戏.你和电脑对战.轮到谁的回合,谁翻两张牌.假设两张牌一样,就消掉这两 ...
 - 截止频率-3db
			
关于-3db截止频率 (2013-06-22 10:47:02) 转载▼ 分类: 信号.电路 关于-3db截止频率 为什么当信号衰减了-3db的时候就算是截止频率了.这里面有什么高深的内涵.毕竟这 ...
 - python3 随机生成6位数的验证码
			
python3 随机生成6位数的验证码 要求是数字:0~9 及大小写字母. #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung ...
 - [React] Style the body element with styled-components and "injectGlobal"
			
In this lesson, we see how we can apply styles globally with the "injectGlobal" helper met ...