Codeforces Round #309 (Div. 1) A(组合数学)
题目: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(组合数学)的更多相关文章
- 贪心 Codeforces Round #309 (Div. 2) B. Ohana Cleans Up
题目传送门 /* 题意:某几列的数字翻转,使得某些行全为1,求出最多能有几行 想了好久都没有思路,看了代码才知道不用蠢办法,匹配初始相同的行最多能有几对就好了,不必翻转 */ #include < ...
- 找规律 Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks
题目传送门 /* 找规律,水 */ #include <cstdio> #include <iostream> #include <algorithm> #incl ...
- 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 ...
- 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 ...
- 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/ ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- Linux实现VLAN
交换机的端口有两种配置模式:Access和Trunk. Access口:端口属于VLAN,VLAN ID 1~4096.直接与计算机网卡相连,流入该口的数据包都被打上VLAN的标签. Trunk口:允 ...
- Linux系统查看本机ip地址
1. 使用ifconfig命令查看inet对应的ip地址就是 2. 如果不能使用ifconfig命令,需要安装net-tools工具,使用yum install net-tools安装即可.
- java线程学习之线程创建
线程是程序控制的一个内部数据流.线程的状态转化如下 或者 在java中创建线程有两种方式: 1.实现runnable接口(这个比较好,推荐这个.原因是:用的时候比较灵活,相比较继承Thread类,用接 ...
- [c/c++] programming之路(25)、字符串(六)——memset,Unicode及宽字符,strset
一.memset #include<stdio.h> #include<stdlib.h> #include<memory.h> void *mymemset(vo ...
- 【做题】51Nod1766树上的最远点对——直径&线段树
原文链接 https://www.cnblogs.com/cly-none/p/9890837.html 题意:给出一棵大小为\(n\)的树,边有边权.\(m\)次询问,每次给出两个标号区间\([a, ...
- c# 7.1 Async Main方法
安装 .net framework sdk 7.1 新建一个 .net framework 7.1 的程序 在程序的工程文件的第一个 PropertyGroup 节点下加入以下子属性 <L ...
- SQLServer 对已有数据表添加自增主键
最近在做老表的数据整理,发现有的表没有主键标识,.NET Core 无法一键生成模型,需要带有主键的表才可以,所以需要针对已有数据添加主键,这是我找到的两种方式. 1. 主键为int 或者bigint ...
- springboot使用@Schednled 注解实现定时任务
part 1: @Component public class Scheduled { SimpleDateFormat dateFormat = new SimpleDateFormat(" ...
- [原]jsbsim 自动驾驶c310ap文件改写
<?xml version="1.0"?> <!-- Author: 南水之源 Date: 1 January 2019 Function: A-320 auto ...
- Rails-Treasure chest2 嵌套表单;
嵌套表单1-1 嵌套表单1-多 选日期时间的UI (一个jquery Plugin) 拆除前后台css和js Rich Editor, 显示输入的HTML tag 批次编辑/删除 嵌套表单1-1 核心 ...