给定一个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. 6.0RMB MP3所看到的……

    产品篇:          偶然看到这个商品信息,作为电子开发人员,首先想到的便是采用了哪家芯片方案,怎么做到这么低的价格!     于是立刻买了一台回来,拆机如下:          成本BOM: ...

  2. 450A - Jzzhu and Children 找规律也能够模拟

    挺水的一道题.规律性非常强,在数组中找出最大的数max,用max/m计算出倍数t,然后再把数组中的书都减去t*m,之后就把数组从后遍历找出第一个大于零的即可了 #include<iostream ...

  3. ThinkPhp学习13

    原文:ThinkPhp学习13 简单登录验证 创建Login类 <?php class LoginAction extends Action { function index(){ $this- ...

  4. 与众不同 windows phone (27) - Feature(特性)之搜索的可扩展性, 程序的生命周期和页面的生命周期, 页面导航, 系统状态栏

    原文:与众不同 windows phone (27) - Feature(特性)之搜索的可扩展性, 程序的生命周期和页面的生命周期, 页面导航, 系统状态栏 [索引页][源码下载] 与众不同 wind ...

  5. Spring MVC+JSP实现三级联动

    jsp代码 <script type="text/javascript"> $(function() { initProvinces(); }); /** * 获取省列 ...

  6. JS Bin Tips and Bits • About

    JS Bin Tips and Bits • About   About Who built this? JS Bin was built by Remy Sharp and is completel ...

  7. java大数处理

    比较两个数大小 import java.math.*; import java.util.*; public class Main { public static void main(String[] ...

  8. 【Android】读取sdcard卡上的全部图片而且显示,读取的过程有进度条显示

    尽管以下的app还没有做到快图浏览.ES文件浏览器的水平,遇到大sdcard还是会存在读取过久.内存溢出等问题,可是基本思想是这种. 例如以下图.在sdcard卡上有4张图片, 打开app,则会吧sd ...

  9. 事件总线帧---Otto

    我们如果这样一种业务场景.如今在做一款及时聊天应用,我们在聊天页面进行收发信息.同一时候也要实时更新前一页面的聊天记录,这时我们该怎样去实现?说说我曾经的实现策略.我使用的是广播接收器BroadCas ...

  10. AccountManager使用教程

    API解读 这个类给用户提供了集中注冊账号的接口.用户仅仅要输入一次账户password后,就能够訪问internet资源. 不同的在线服务用不同的方式管理用户,所以account manager 为 ...