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 ...
随机推荐
- Gis数据处理2 ---8.18
1空间参考: 了解大地水准面,参考椭球体,基准面的概念 以及之间的关系 基准面描述的是参考椭球体中心 跟地心的关系 我们常说的北京54.西安80.CGCS2000,实际上指的是我国的三个大地基 ...
- ACM-ICPC 2018 南京赛区网络预赛 Solution
A. An Olympian Math Problem cout << n - 1 << endl; #include <bits/stdc++.h> using ...
- mybites
[mybatis-spring] http://www.mybatis.org/spring/zh/index.html 使用spring mybatis 中间件 方便使用 mybatis [myba ...
- dp小总结
写在前面 Just some easy problem solving with dynamic programming. (Given me a dynamic programming table, ...
- keepalived + lvs
Keepalived原理 Keepalived原理 keepalived也是模块化设计,不同模块复杂不同的功能,下面是keepalived的组件 core check vrrp libipfwc li ...
- CentOS 6.5安装squashfs-tools
在sourceforge.net网站下载源码包 需要安装的依赖项有zlib-devel.xz-devel.x86_64 修改Makefile文件以支持xz压缩的squashfs文件,去掉Makefil ...
- shell实现自动部署两台tomcat项目Ⅱ
本次分为3个脚本, scp.sh放进第一台机器(负责传输文件), schenglee.sh放进第一台机器(自动部署), schenglee2.sh放进第二台机器(自动部署) 环境 tomcat1: 1 ...
- 用python画小王八裤(turtle库)
一,采用Python语言如何画一朵玫瑰花 工具/原料 Python语言包 Win10 一. 准备 1. 打开界面: 打开python 2. 创建文件 二. 编程 1. 编写画图: from turtl ...
- Linux下Shell的for循环语句
第一类:数字性循环-----------------------------for1-1.sh #!/bin/bash ;i<=;i++)); do + ); done ------------ ...
- vue--音乐播放器
github: https://github.com/vinieo/vue-music 效果: 基础组件: 1.confirm:确认对话框组件 2.listview:通讯录列表组件 3.loading ...