HDU 5698——瞬间移动——————【逆元求组合数】
瞬间移动
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 205 Accepted Submission(s): 109

两个整数n,m(2≤n,m≤100000)
#include <iostream>
#include<algorithm>
#include<stdio.h>
#include<vector>
using namespace std;
typedef long long LL;
const int maxn = 1e5+200;
const int mod = 1e9+7;
#define mid (L+R)/2
#define lson rt*2,L,mid
#define rson mid+1,R
LL quick(LL x, LL n){
if(n == 0)
return 1;
LL ret = 1;
while(n){
if(n&1)
ret = (ret*x) % mod;
n = n>>1;
x = (x*x) % mod;
}
return ret;
}
LL fac[maxn], inv[maxn];
LL C(LL n, LL m){
if(n == m) return 1;
if(n < m) return 0;
return (fac[n] * inv[n-m]) % mod * inv[m] % mod;
}
int main(){
int n , m;
fac[0] = 1;
for(int i = 1; i <= maxn - 10; i++){
fac[i] = (fac[i-1] * i) % mod;
}
// for(int i = 1; i <= 100100; i++){ //这种比较慢,可以有O(n)的递推
// inv[i] = quick(fac[i] ,(LL)mod-2);
// }
inv[maxn-10] = quick(fac[maxn-10],mod-2);
for(int i = maxn-11; i >= 1; i--){ //递推求解阶乘的逆元
inv[i] = inv[i+1] * (i+1) % mod;
}
while(scanf("%d%d",&n,&m)!=EOF){
if(n > m)
swap(n,m);
n--; m--;
LL ans = 1;
for(int i = 1; i < n; i++){
ans = (ans + (C(n-1,i)*C(m-1,i)) % mod) % mod;
}
printf("%d\n",ans%mod);
} return 0;
}
HDU 5698——瞬间移动——————【逆元求组合数】的更多相关文章
- 牛客小白月赛14 -B (逆元求组合数)
题目链接:https://ac.nowcoder.com/acm/contest/879/B 题意:题目意思就是求ΣC(n,i)pi(MOD+1-p)n-i (k<=i<=n),这里n,i ...
- Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 【逆元求组合数 && 离散化】
任意门:http://codeforces.com/contest/689/problem/E E. Mike and Geometry Problem time limit per test 3 s ...
- HDU 5698 瞬间移动 数学
瞬间移动 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5698 Description 有一个无限大的矩形,初始时你在左上角(即第一行第一列),每次 ...
- HDU 5698 瞬间移动
瞬间移动 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- hdu 5698 瞬间移动(排列组合)
这题刚看完,想了想,没思路,就题解了 = = 但不得不说,找到这个题解真的很强大,链接:http://blog.csdn.net/qwb492859377/article/details/514781 ...
- HDU 5852 Intersection is not allowed!(LGV定理行列式求组合数)题解
题意:有K个棋子在一个大小为N×N的棋盘.一开始,它们都在棋盘的顶端,它们起始的位置是 (1,a1),(1,a2),...,(1,ak) ,它们的目的地是 (n,b1),(n,b2),...,(n,b ...
- 数学--数论--HDU 4675 GCD of Sequence(莫比乌斯反演+卢卡斯定理求组合数+乘法逆元+快速幂取模)
先放知识点: 莫比乌斯反演 卢卡斯定理求组合数 乘法逆元 快速幂取模 GCD of Sequence Alice is playing a game with Bob. Alice shows N i ...
- 求组合数、求逆元、求阶乘 O(n)
在O(n)的时间内求组合数.求逆元.求阶乘.·.· #include <iostream> #include <cstdio> #define ll long long ;// ...
- hdu 2519 求组合数
求组合数 如果求C5 3 就是5*4*3/3*2*1 也就是(5/3)*(4/2)*(3/1) Sample Input5 //T3 2 //C3 25 34 43 68 0 Sample Outpu ...
随机推荐
- 【Selenium专题】 FAQ_对象识别_Compound class names are not supported
测试代码 public void login(){ WebDriver driver = new ChromeDriver(); driver.get("http://IP:Port/cli ...
- UI Automator Viewer的使用
uiautomatorviewer是android SDK自带的工具.通过截屏并分析XML布局文件的方式,为用户提供控件信息查看服务.该工具位于SDK目录下的tools\bin子目录下.可以看到,它是 ...
- 如何在linux上安装使用virt-manager
环境是centos6.5-64位操作系统. 1.准备yum源: 将CentOS6-Base-163.repo 下载到目标主机的/etc/yum.repos.d/目录. cd /etc/yum.repo ...
- jqGrid-基础篇
jqGrid 是一个用来显示网格数据的jQuery插件,通过使用jqGrid可以轻松实现前端页面与后台数据的ajax异步通信. 一.jqGrid特性 基于jquery UI主题,开发者可以根据客户要 ...
- Spring定时任务执行
备注:这个是基于搭建好spring的环境下的 注解方式: 1.定时任务类 package com.test;import java.util.Date;import org.springframewo ...
- STR[#6]
photo 小明在旅游的路上看到了一条美丽的河,河上有许多船只,有的船只向左航行,有的船只向右航行.小明希望拍下这一美丽的风景,并且把尽可能多的船只都完整地拍到一张照片中. 小明位于河的边上,并且可以 ...
- AtCoder Grand Contest 031题解
题面 传送门 题解 比赛的之后做完\(AB\)就开始发呆了--简直菜的一笔啊-- \(A - Colorful\ Subsequence\) 如果第\(i\)个字母选,那么它前面任意一个别的字母的选择 ...
- Python3.6引入的f-string 与 Python 3的新的特性:类型注解;
f-string 1.介绍 f-string(formatted string literals):格式化字符串常量,是Python3.6新引入的一种字符串格式化方法,使格式化字符串的操作更加简便. ...
- Java函数的联级调用
String类的方法可以连续调用: String str="abc"; String result=str.trim().toUpperCase().concat("de ...
- Pycharm与github的秘密
GIT介绍 GIT文章请看老男孩教育-银角大王的博客: http://www.cnblogs.com/wupeiqi/articles/7295372.html Git 是一个开源的分布式版本控制软件 ...