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
题意:
有k种颜色,每种颜色对应a[i]个球,球的总数不超过1000
要求第i种颜色的最后一个球,其后面接着的必须是第i+1种颜色的球
问一共有多少种排法
对于每一种颜色的求有当前所剩的总位数sum,当前颜色个数a
C(sum - 1, a - 1);
乘上所有的情况就好了;
另外组合数要打表求出;
C[i][j] = C[i - 1][j] + C[i - 1][j - 1];杨辉三角的求法;
代码:
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#define LL __int64
using namespace std;
const int MAXN = ;
const LL MOD = ;
int a[MAXN];
LL C[MAXN][MAXN];
void db(){
C[][] = ;
C[][] = ; C[][] = ;
for(int i = ; i < MAXN; i++){
C[i][] = C[i][i] = ;
for(int j = ; j < i; j++){
C[i][j] = C[i - ][j] + C[i - ][j - ];
C[i][j] %= MOD;
}
}
}
int main(){
int k;
db();
while(~scanf("%d", &k)){
LL sum = ;
for(int i = ; i <= k; i++){
scanf("%d", a + i);
sum += a[i];
}
LL ans = ;
for(int i = k; i >= ; i--){
ans *= C[sum - ][a[i] - ];
ans %= MOD;
// printf("%d %d %d\n", sum - 1, a[i] - 1, C[sum - 1][a[i] - 1]);
sum -= a[i];
}
printf("%I64d\n", ans);
}
return ;
}
Kyoya and Colored Balls(组合数)的更多相关文章
-
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 ...
-
Codeforces554 C Kyoya and Colored Balls
C. Kyoya and Colored Balls Time Limit: 2000ms Memory Limit: 262144KB 64-bit integer IO format: %I64d ...
-
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 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 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 ...
-
Codeforces554C:Kyoya and Colored Balls(组合数学+费马小定理)
Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are ...
随机推荐
-
玩转JavaScript OOP[1]&mdash;&mdash;复杂类型
概述 在JavaScript中,我们可以使用函数.数组.对象,以及日期.正则等一些内置类型的实例,它们都是复杂类型的表现.从本质上讲,这些复杂类型都是Object类型.本篇将主要介绍三种Object类 ...
-
通过cygwin安装openSSH
openSSH的安装是学习hadoop必不可少的一步,如果ssh装不好,hadoop的安装会进行不下去.本人初学hadoop时发现以前安装ssh走了一些弯路,现在又有了一些认识,所以重写了这篇日志,供 ...
-
java多线程详解(3)-线程的互斥与同步
前言:前一篇文章主要描述了多线程中访成员变量与局部变量问题,我们知道访成员变量有线程安全问题,在多线程程序中 我们可以通过使用synchronized关键字完成线程的同步,能够解决部分线程安全问题 在 ...
-
【Alpha阶段】第八次Scrum例会
会议信息 时间:2016.11.01 21:30 时长:60min 地点:大运村1号公寓5楼楼道 类型:日常Scrum会议 NXT:2016.11.03 21:30 个人任务报告 姓名 今日已完成Is ...
-
最受欢迎的iOS第三方SDK
http://www.raywenderlich.com/forums/viewtopic.php?t=4496
-
C# 添加、获取及删除PDF附件
C# 添加.获取及删除PDF附件 前言 附件在PDF文档中很常见,这些附件可以是PDF或其他类型的文件.在PDF中,附件有两种存在方式,一种是普通的文件附件(document-level file a ...
-
linux模块驱动之led(ioremap)
一:led内核驱动 (1)在编写led内核驱动时,我们首先要进行内核裁剪,因为友善之臂将LED灯的驱动默认加载到内核中,所以编写模块驱动程序前就要先把原先的LED灯驱动裁剪掉: led驱动在源码里面的 ...
-
RabbitMQ系列(五)使用Docker部署RabbitMQ集群
概述 本文重点介绍的Docker的使用,以及如何部署RabbitMQ集群,最基础的Docker安装,本文不做过多的描述,读者可以自行度娘. Windows10上Docker的安装 因为本人用的是Win ...
-
C#开发微信公众平台-就这么简单(附Demo)转载
C#开发微信公众平台-就这么简单(附Demo) 来源:https://www.cnblogs.com/xishuai/p/3625859.html#!comments 写在前面 阅读目录: 服务号和 ...
-
Redis的消息发布和订阅
Redis的消息发布和订阅 Author:SimpleWu GitHub-redis 什么是消息发布和订阅? Redis 发布订阅(pub/sub)是一种进程间的消息通信模式: 发送者(pub)发送消 ...