题目:http://codeforces.com/contest/553/problem/A

题意:给你k个颜色的球,下面k行代表每个颜色的球有多少个,规定第i种颜色的球的最后一个在第i-1种颜色的球的最后一个的前面

思路:首先我们想如果是第i种颜色,我们首先必须把这个颜色留下一个,留下的这个球前面的球的个数是前面颜色的总和+这个颜色数-1,

我们想这个颜色的位置数如何安排,即 C(总座位数,要安排的个数),i-1种颜色也是相同的道理,所以我们推出公式

累加球的个数 sum

当前颜色的球的个数num

那么当前颜色的安排个数 即  C(sum-1,num-1)

然后累乘所有的方案数即是答案

这里我们是用卢卡斯定理求的大组合数取模

#include<cmath>
#include<cstdio>
#define ll long long
#define mod 1000000007
using namespace std;
const int maxn = ;
ll dp[maxn],inv[maxn],fac[maxn],inv_fac[maxn];
void init()
{
inv[]=inv[]=inv_fac[]=fac[]=;
dp[]=;dp[]=;
for(int i=; i<maxn; i++) inv[i]=inv[mod%i]*(mod-mod/i)%mod;
for(int i=; i<maxn; i++) fac[i]=fac[i-]*i%mod;
for(int i=; i<maxn; i++) inv_fac[i]=inv_fac[i-]*inv[i]%mod;
for(int i=; i<maxn; i++) dp[i]=(i-)*(dp[i-]+dp[i-])%mod;
}
ll C(int n,int m)
{
return fac[n]*inv_fac[m]%mod*inv_fac[n-m]%mod;
}
int main()
{
init();
ll n,x;
ll sum=;
ll flag=;
scanf("%lld",&n);
for(int i=;i<n;i++){
scanf("%lld",&x);
sum+=x;
flag=(flag*C(sum-,x-))%mod;
}
printf("%lld",flag);
}

Codeforces Round #309 (Div. 1) A(组合数学)的更多相关文章

  1. 贪心 Codeforces Round #309 (Div. 2) B. Ohana Cleans Up

    题目传送门 /* 题意:某几列的数字翻转,使得某些行全为1,求出最多能有几行 想了好久都没有思路,看了代码才知道不用蠢办法,匹配初始相同的行最多能有几对就好了,不必翻转 */ #include < ...

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

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

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

  4. Codeforces Round #309 (Div. 1) C. Love Triangles dfs

    C. Love Triangles Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/553/pro ...

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

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

  7. Codeforces Round #309 (Div. 2) B. Ohana Cleans Up 字符串水题

    B. Ohana Cleans Up Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/554/pr ...

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

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

随机推荐

  1. HP Jack介绍

    转载:https://www.cnblogs.com/Peter-Chen/p/3999212.html 目前市场上耳机分为4环耳机(图1所示,iphone型)和3环耳机(图2所示).4环耳机称为he ...

  2. Python Logging模块 输出日志颜色、过期清理和日志滚动备份

    # coding:utf-8 import logging from logging.handlers import RotatingFileHandler # 按文件大小滚动备份 import co ...

  3. go中 -strconv包的使用

    strconv 包中的函数和方法 // atob.go ------------------------------------------------------------ // ParseBoo ...

  4. Linux curl 网络访问

    Linux curl 网络访问 参数详解 -a/--append 上传文件时,附加到目标文件 -A/--user-agent <string> 设置用户代理发送给服务器 -anyauth ...

  5. 使用curl自动签到smzdm

    curl -H 'cookie:urcookies' -e 'http://www.smzdm.com/qiandao/' -k 'https://zhiyou.smzdm.com/user/chec ...

  6. ORA-55617解决方法

    昨天一测试环境出现异常ORA-55617: Flashback Archive "XXXXX" runs out of space and tracking on "XX ...

  7. 【Python65--tkinter:button】

    一.需求:在Label页面增加一个按钮,点击此按钮,页面内容进行变化 思路: 1.上面放一个Label,下面放一个Button 2.采用frame框架 from tkinter import * #定 ...

  8. ant常用的内置 task转自https://www.cnblogs.com/baicj/archive/2015/12/21/5063608.html

    ant 例如: <target name="callProjectB"> <echo message="In projectA calling proj ...

  9. jQuery实现淘宝购物车小组件

    我爱撸码,撸码使我感到快乐! 大家好,我是Counter,本章将实现淘宝购物车小组件, 用原生js可以实现吗,当然可以,可是就是任性一回,就是想用jQuery 来实现下.HTML代码不多才4行,CSS ...

  10. HAProxy + Keepalived + Flume 构建高性能高可用分布式日志系统

    一.HAProxy简介 HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代 理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案.HAProxy特别适用于那些负载特大的web站点, ...