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 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 ibefore
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 这道题让我学会了组合数的计算。由于直接用组合数公式会导致结果不准确。如C(100,50)这样,假设用乘一个数除一个数的方法,那么可能会导致不能整除而会发生误差。 思路:若前i种颜色的方法总数是f(i),那么第i+1种颜色的方法总数是f(i+1)=f(i)*C(sum(i+1)-1,a[i+1]-1),当中sum(i+1)是前i+1种颜色的个数总和。#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
#define ll __int64
#define maxn 1000000007
int a[1600];
ll c[1050][1060];
ll sum; int main()
{
int n,m,i,j,sum1;
for(i=1;i<=1000;i++)c[i][0]=1; for(i=1;i<=1000;i++){
for(j=1;j<=i;j++){
if(i==j)c[i][j]=1;
else if(i>j)
c[i][j]=(c[i-1][j]+c[i-1][j-1])%maxn;
}
} while(scanf("%d",&n)!=EOF)
{
for(i=1;i<=n;i++){
scanf("%d",&a[i]);
}
sum1=a[1];sum=1;
for(i=2;i<=n;i++){
sum1+=a[i];
//printf("%d %d\n",a[i]-1,sum1-1);
sum=(sum*c[sum1-1][a[i]-1])%maxn;
//sum=(sum*f(a[i]-1,sum1-1))%maxn;
//printf("%lld\n",sum);
}
printf("%I64d\n",sum);
}
return 0;
}
Codeforces Round #309 (Div. 2) 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 ...
- 找规律 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 #309 (Div. 2) B. Ohana Cleans Up
题目传送门 /* 题意:某几列的数字翻转,使得某些行全为1,求出最多能有几行 想了好久都没有思路,看了代码才知道不用蠢办法,匹配初始相同的行最多能有几对就好了,不必翻转 */ #include < ...
- 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 Round #309 (Div. 2)
A. Kyoya and Photobooks Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He ha ...
随机推荐
- table中的td等长(不随内容大小变化)
使用的table时候发现td的长度是随着内容的大小而变化的,但是有的时候我们不希望这样.想要td等长可以在 tbale中加上 style=“table-layout:fixed” ...
- AdvStringGrid 标题头
标题头内容: 字体: 标题头高度: 头的对齐方式:
- C#连接mariadb代码及方式
不负责任的说MariaDb和MySQL很多都是通用的,因为来自同一个爹... 和MySQL连接方式差不多 首先配置好你的MariaDb,创建test数据库,在test里创建MyTable表,脚本如下( ...
- centos7 配置ftp访问
vsftp安装 创建用户 并限定用户在自己的目录 1.查看是否已经安装了vsftpd vsftpd -version 2.安装vsftpd(CentOS7) yum install -y vsftpd ...
- Sample ASP.NET IHttpHandler
LoggerHandler.cs using System; using System.Collections.Generic; using System.Diagnostics; using Sys ...
- sql结合通配符来自定义转义字符
1.使用 ESCAPE 关键字,定义转义符.在模式中,当转义符置于通配符之前时,该通配符就解释为普通字符.例如,要搜索在任意位置包含字符串 5% 的字符串,请使用: WHER ...
- ubuntu编译安装postgresql
闲着没事用源码编译安装了postgresql,遇到了不少故障,记录一下. 1:用./configure配置时发生错误.看信息说是缺少相关包.有什么readline,zlip等. 我配置的很简单,只是配 ...
- EcOS安装
从ubuntu 拷贝到 centos cd /media ls cd ./sf_EcOS 这个目录就是共享目录,名字可能不一样 cp -r studio.zip /home/ 1. 查看版本 cent ...
- Block的基本用法
NSString* (^myBlock)(NSString*, int); myBlock = ^(NSString *name, int age){ return [NSString stringW ...
- Django2.0中URL的路由机制
路由是关联url及其处理函数关系的过程.Django的url路由配置在settings.py文件中ROOT_URLCONF变量指定全局路由文件名称. Django的路由都写在urls.py文件中的ur ...