给定一个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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 找规律 Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks

    题目传送门 /* 找规律,水 */ #include <cstdio> #include <iostream> #include <algorithm> #incl ...

  4. Codeforces A. Kyoya and Colored Balls(分步组合)

    题目描述: Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  5. 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 ...

  6. Codeforces Round #309 (Div. 2)

    A. Kyoya and Photobooks Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He ha ...

  7. 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 ...

  8. Codeforces554 C Kyoya and Colored Balls

    C. Kyoya and Colored Balls Time Limit: 2000ms Memory Limit: 262144KB 64-bit integer IO format: %I64d ...

  9. Kyoya and Colored Balls(组合数)

    Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

随机推荐

  1. uploadfiy使用

    动态加参数:$("#file_upload").uploadify("settings", "formData", { knowledgeI ...

  2. 14.5.5 Creating a File-Per-Table Tablespace Outside the Data Directory

    14.5.5 Creating a File-Per-Table Tablespace Outside the Data Directory 创建一个File-Per-Table Tablespace ...

  3. MongoDB学习笔记(一)

    MongoDB的介绍我就不说了.直接开始环境的搭建和连接.在这个之前,向大家介绍几个关于MongoDB的网站. 1.  https://www.mongodb.com/ MongoDB的官网. 2. ...

  4. python 内存泄露的诊断 - 独立思考 - ITeye技术网站

    python 内存泄露的诊断 - 独立思考 - ITeye技术网站 python 内存泄露的诊断 博客分类: 编程语言: Python Python多线程Blog.net  对于一个用 python ...

  5. Android面向HTTP协议发送get请求

    /** * 採用get请求的方式 * * @param username * @param password * @return null表示求得的路径有问题,text返回请求得到的数据 */ pub ...

  6. 无锁队列--基于linuxkfifo实现

    一直想写一个无锁队列,为了提高项目的背景效率. 有机会看到linux核心kfifo.h 原则. 所以这个实现自己仿照,眼下linux我们应该能够提供外部接口. #ifndef _NO_LOCK_QUE ...

  7. [Android学习笔记]LayoutInflater的使用

    LayoutInflater用于动态载入布局,然后获取到布局中定义完成的控件引用 常在动态加载布局,和Adapter中用到 使用步骤:1.通过LayoutInflater加载xml布局文件2.从载入的 ...

  8. 慎得慌风 656ik67o

    http://photo.163.com/q/7634581 http://photo.163.com/q/7634580 http://photo.163.com/q/7634577 http:// ...

  9. No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=arm64, VALID_ARCHS=armv7 armv7s)

    问题: No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=arm64, VALID_ARCHS=armv7 armv ...

  10. ubuntu下海信Hisense E920 usb连接不上的处理与adb的连接

    解决lssub未能发现海信Hisense USB设置:选择 天翼宽带连接 如下所示: luogw@luogw-ThinkPad-Edge:~$ lsusb Bus 001 Device 002: ID ...