ABC156E
题目链接
也是简单的组合数学问题,每个位置可以移动走,也可以移动来,那么我们就需要找最终的状态,也就是最终的0的个数
假设有m个0,就有n-m个非0空位,选择0的组合数为\(\textrm{C}_{n}^{m}\),这m个位置转移到n-m个位置的组合数为\(\textrm{D}_{n-m}^{m}\),意思是从n-m个非0的部分选m个来接受这些转移来的,转换成组合数公式有:\(\textrm{D}_{n-m}^{m}\) = \(\textrm{C}_{n-1}^{n-m-1}\),也就是说,x个中选y个,可以重复的组合数为\(\textrm{C}_{x+y-1}^{x-1}\)
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL;
const int maxn = 2e5+5;
const LL MOD = 1e9+7;
LL F[maxn], Finv[maxn], inv[maxn];
void prework() {
inv[1] = 1;
for(int i = 2; i < maxn; ++i) {
inv[i] = (MOD - MOD / i) * 1LL * inv[MOD % i] % MOD;
}
F[0] = Finv[0] = 1;
for(int i = 1; i < maxn; ++i) {
F[i] = F[i-1] * 1LL * i % MOD;
Finv[i] = Finv[i-1] * 1LL * inv[i] % MOD;
}
}
LL comb(int n, int m) { //C(n, m)
if(n < m || m < 0) return 0;
return F[n] * 1LL * Finv[n-m] % MOD * Finv[m] % MOD;
}
void run_case() {
prework();
LL n, k, ans = 0;
cin >> n >> k;
for(int i = 0; i < n; ++i) {
if(i > k) break;
ans = (ans + comb(n, i) * comb(n-1, n-i-1)%MOD + MOD) % MOD;
}
cout << ans;
}
int main() {
ios::sync_with_stdio(false), cin.tie(0);
cout.flags(ios::fixed);cout.precision(10);
run_case();
cout.flush();
return 0;
}
ABC156E的更多相关文章
随机推荐
- Git 添加远程github仓库的时候提示错误:fatal: remote origin already exists.
1.先删除远程 Git 仓库 $ git remote rm origin 2.再添加远程 Git 仓库 $ git remote add origin git@github.com:wsydxian ...
- git免密拉取代码
里介绍通过ssh公钥的方式免密拉取代码 以linux服务器为例,windows方式是一样的 1.用命令生成ssh key ssh-keygen -t rsa -C "xx@xxxcom&qu ...
- Docker+JMeter单机版+Nginx
基于JMeter5.1.1+Nginx1.12.2JMeter发起压测 Nginx作为文件服务器 一.目录结构: Dockerfile文件: FROM ubuntu:18.04# 基础镜像 MAIN ...
- MySQL中int(11)的意思
参考文献:https://segmentfault.com/a/1190000012479448 int(11)中的11代表的是字符的显示宽度,在字段类型为int时,无论你显示宽度设置为多少,int类 ...
- maven web报错:org.apache.jasper.JasperException: Unable to compile class for JSP
原博文地址:https://blog.csdn.net/ken1583096683/article/details/80837281 maven web项目启动没问题,访问页面就报错:org.apac ...
- JS 数组克隆方法总结
ES5 方法总结 1.slice let arr = [2,4,434,43] let arr1= arr.slice() arr[0] = 'a' console.log(arr,arr1) // ...
- Apache如何开启Gzip压缩
https://teddysun.com/326.html 在开启 Gzip 之前,需先确认 Apache 的配置文件中有没有加载 mod_deflate 和 mod_headers 模块. 打开Ap ...
- vue 项目太大, 导致 javascript heap out of memory
原因: node 环境, 对单个进程的内存是有限制的, 但是现在前端项目太大, 所以我们需要根据当前机器环境, 手动加大node的内存限制 安装包 npm i increase-memory-limi ...
- IntelliJ IDEA 2017.3尚硅谷-----滚轮修改字体大小
- drf三大组件之频率认证组件
复习 """ 1.认证组件:校验认证字符串,得到request.user 没有认证字符串,直接放回None,游客 有认证字符串,但认证失败抛异常,非法用户 有认证字符串, ...