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 ...
随机推荐
- cct信息安全
基本信息 全国计算机等级考试三级教程——信息安全技术(2016年版) 作 者:教育部考试中心 编 出 版 社:高等教育出版社 出版时间:2015-12-1 ISBN:9787040443035 ...
- 第十七篇:实例分析(1)--初探WDDM驱动学习笔记(八)
第四篇(VidPN)中提到过MIRROR驱动. 在进入本篇的实际内容前, 带着好奇心, 想请教CSDN中的显卡驱动方面的大虾, 怎样才干把这个驱动玩起来, 这个驱动的作用是什么,等等, 敬请不吝赐教. ...
- WinDBG调试技巧
参考链接:http://wenku.baidu.com/view/4e58744dcf84b9d528ea7a42.html
- jTDS驱动兼容性问题
Java连接SQL Server 2000数据库时,有两种方法: (1)通过Microsoft的JDBC驱动连接.此JDBC驱动共有三个文件,分别是mssqlserver.jar.msutil.jar ...
- 你真的了解JAVA中与Webservice相关的规范和实现吗?
非常多人在项目中使用Webservice,仅仅是知道怎样公布Webservice,怎样调用Webservice,但真要论其来龙去脉,还真不一定清楚. 一切一切还要从我们伟大的sun公司规范说起. JA ...
- 空间参考系统与WKT解析
空间参考系统与WKT解析 1.为什么要空间参考系统? 空间参考系统,也称为坐标系统.在GIS中为地理数据定位的基准,假设给你一个坐标(442281.875,4422651.589).如果不给你空间参考 ...
- 关于使用commons-email包测试发送邮件遇到的问题
项目中有个需求是这样的:客户办理某一项业务,当用户成功提交业务办理信息后,系统生成一个业务随机码给用户,以此作为以后的业务办理结果查询依据.鉴于随机码较长,方便用户记录,在生成随机码的同时,提供用户发 ...
- Typings实现智能
在Visual Studio Code中通过Typings实现智能提示功能 前言 我们知道在IDE中代码的智能提示几乎都是标配,虽然一些文本编辑器也有一些简单的提示,但这是通过代码片段提供的.功能 ...
- HDU ACM 1054 Strategic Game 二分图最小顶点覆盖?树形DP
分析:这里使用树形DP做. 1.最小顶点覆盖做法:最小顶点覆盖 == 最大匹配(双向图)/2. 2.树形DP: dp[i][0]表示i为根节点,而且该节点不放,所需的最少的点数. dp[i][1]表示 ...
- WebService开启远程测试
WebService部署成站点之后,如果在本地测试webservice的接口可以运行,在远程却显示“测试窗体只能用于来自本地计算机的请求”或者"The test form is only a ...