Codeforces Round#309 C Kyoya and Colored Balls
给定一个k表示颜色的种类从1到k
然后接下来k行, 每行一个数字, 代表该颜色的球有多少个
这些球都放在一个包中,然后依次拿出。 要求颜色i的最后一个球, 必须要排在颜色i+1的最后一个球前面, 1<=i<=k-1
我们先从小规模判断起来,
当k=2时,
当k=3时, a[2]-1个球可以在已经排好的 每个排列中的 a[0]+a[1] 个球中随便插, 因为已经排好(即位置不能变了),所以a[0]+a[1]个球可以看做是同一种颜色的球
那么这个随便插就相当于有多少种不同的排列。 可知是
这是在每个排列中随便插的结果, 总共有
个排列, k=3时,总的取法是两个式子相乘
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <math.h>
using namespace std;
#pragma warning(disable:4996)
typedef long long LL;
const int INF = <<;
/* */
const int MOD = ;
int a[ + ];
LL fact[]; LL MyPow(LL a, LL b)
{
LL ret = ;
while (b)
{
if (b & )
ret = ret * a % MOD;
a = a * a % MOD;
b >>= ;
}
return ret;
}
LL C(int n, int m)
{
if (m > n || m < ) return ;
LL a = fact[n], b = fact[n - m] * fact[m] % MOD;
return a * MyPow(b, MOD - ) % MOD;//除以一个数,等于乘以这个数的乘法逆元, 然后是在MOD的情况下
} int main()
{
fact[] = ;
for (int i = ; i < ; ++i)
fact[i] = fact[i - ] * i %MOD;
int n;
scanf("%d", &n);
for (int i = ; i < n; ++i)
scanf("%d", &a[i]);
int sum = a[];
LL ans = ;
for (int i = ; i < n; ++i)
{
sum += a[i];
ans = ans * C(sum - , sum - a[i] - ) % MOD;
}
printf("%I64d\n", ans);
return ;
}
为什么在取模的情况下,除以一个数 会等于乘以这个数的逆元呢?

那么在%p的情况下 乘以xb, 那么就相当于乘以1, 然后就可以把分母给约掉。 而x叫做b模p的乘法逆元
Codeforces Round#309 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 ...
- 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
题目传送门 /* 找规律,水 */ #include <cstdio> #include <iostream> #include <algorithm> #incl ...
- 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 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 Round #309 (Div. 2)
A. Kyoya and Photobooks Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He ha ...
- 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 ...
- Codeforces554 C Kyoya and Colored Balls
C. Kyoya and Colored Balls Time Limit: 2000ms Memory Limit: 262144KB 64-bit integer IO format: %I64d ...
- Kyoya and Colored Balls(组合数)
Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
随机推荐
- 关于ListCtrol自绘的技巧
一.给控件添加排序功能report风格的list控件很多情况下都需要支持排序功能,而且最好支持按不同列进行排序.CListCtrl的类方法SortItems支持排序功能,但是在排序过程中,两个数据真正 ...
- Redisql: the lightning fast data polyglot【翻译】 - Linvo's blog - 博客频道 - CSDN.NET
Redisql: the lightning fast data polyglot[翻译] - Linvo's blog - 博客频道 - CSDN.NET Redisql: the lightnin ...
- ExtJs4 笔记(8) Ext.slider 滚轴控件、 Ext.ProgressBar 进度条控件、 Ext.Editor 编辑控件
本篇要登场的有三个控件,分别是滚轴控件.进度条控件和编辑控件. 一.滚轴控件 Ext.slider 1.滚轴控件的定义 下面我们定义三个具有代表意义滚轴控件,分别展示滚轴横向.纵向,以及单值.多值选择 ...
- 2014年Windows平台软件推荐:神器小工具(骨灰级
原文 http://www.wtoutiao.com/a/120621.html 底层工具 “If you know how to use Process Monitor competently, ...
- 总结showModalDialog在开发中的一些问题
一.在页面调用window.open()函数后,可以直接在打开的页面中用window.opener来调用父页面的方法,然而如果用showModalDialog打开一个模态窗口,就不能通过window. ...
- password加密问题
password加密问题 个人信息:就读于燕大本科软件project专业 眼下大三; 本人博客:google搜索"cqs_2012"就可以; 个人爱好:酷爱数据结构和算法,希望将来 ...
- 【ALearning】第二章 Androidproject知识介绍
本章介绍了主要的初步Androidproject成立了一个开发环境.为了Android意识的整体项目和理解.本章包含Android开发环境的搭建.第一Android工程Hello World与Andr ...
- HDU 4643 GSM 简单计算几何
今天比赛的时候略坑, admin告诉我询问Q的个数不超过n^2, 赛后敲了个 O(Q*m^3)的复杂度,但这个复杂度常数比较低,可能在除以个小常数, 300ms过了,真心无语,数据应该水了吧,比赛的时 ...
- mysql增量ID
启动值更改方法
在mysql很多朋友感到场AUTO_INCREMENT增量型ID值它不能被改变,其实这种认识是错误的,这里mysql增量ID开始值更改和设置. 设置自动递增字段的通常的方法: 格时加入: create ...
- Heritrix与Nutch对比
Nutch 开发语言:Java http://lucene.apache.org/nutch/ 简介: Apache的子项目之一,属于Lucene项目下的子项目. Nutch是一个基于Lucene,类 ...