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 ...
随机推荐
- Android之常用开发框架
1.Rajawali介绍:安卓的OpenGL ES 2.0/3.0 引擎.可以用于制作普通应用或者动态壁纸,当然也可以用于制作游戏.项目地址: https://github.com/Rajawali/ ...
- c# 类的反射实例 (GetType().Invoke().GetMethod().CreateInstance())
原文:http://www.cnblogs.com/chenwei19/archive/2009/02/04/1384034.html Class1和Form 窗体在同一个命名空间 using Sys ...
- OCP2018最新题库,052新题库及答案整理-25题
25.Which is true about logical and physical database structures? (Choose the best answer) A. An undo ...
- kvm虚拟机扩展磁盘空间
kvm虚拟机磁盘空间扩展与xen虚拟机磁盘空间扩展思路一致.原因在于xen/kvm默认的虚拟机磁盘格式为raw,所以方式可以通用. raw磁盘格式扩展思路如下 (1) 新添加一块raw格式的磁盘加入到 ...
- BZOJ4032: [HEOI2015]最短不公共子串(后缀自动机+序列自动机)
题目描述 在虐各种最长公共子串.子序列的题虐的不耐烦了之后,你决定反其道而行之. 一个串的“子串”指的是它的连续的一段,例如bcd是abcdef的子串,但bde不是. 一个串的“子序列”指的是它的可以 ...
- scrapy框架post请求发送,五大核心组件,日志等级,请求传参
一.post请求发送 - 问题:爬虫文件的代码中,我们从来没有手动的对start_urls列表中存储的起始url进行过请求的发送,但是起始url的确是进行了请求的发送,那这是如何实现的呢? - 解答: ...
- [ActionScript 3.0] 如何获得实例对象的类名及类
package { import flash.display.DisplayObject; import flash.display.MovieClip; import flash.display.S ...
- WebStorm 2017 激活方法
https://www.cnblogs.com/woaic/p/6024975.html 注册时,在打开的License Activation窗口中选择“License server”,在输入框输入下 ...
- js中一切都是对象
<script> function cat(){} var cat = new cat(); console.log(cat.constructor) console.log(typeof ...
- docker搭建tomcat环境
1.拉取镜像 docker pull tomcat 2.运行容器 docker run --name tomcat -p : -v /data/tomcat/test:/usr/local/tomca ...