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爬取网易云
from selenium import webdriver from selenium.webdriver import ActionChains from selenium.webdriver.c ...
- 深入了解java虚拟机(JVM) 第四章 对象的创建
一.对象的创建过程 对象的创建过程大致可以分为六步,其中对象的分配尤为重要: 二.对象分配内存 一般来说对象分配内存有两种方式: 第一种是指针碰撞,这是一种比较理想的方式:如果Java堆是绝对规整的: ...
- sql指定值排在前面
示例: SELECT COL1 FROM TABLE1 ORDER BY CASE WHEN COL1 = 'A' THEN 1 ELSE 2 END,COL1;//COL1为A的排在最前面,剩下的按 ...
- ZJOI round1游记
Day 0 到镇海报道了 大佬们太多了--话说镇海的晚饭还真好吃啊-- 听说某人要咱去找bwh--不过咱和他也不是很熟啊--还是算了吧--(才不是因为嫌麻烦懒得去呢) 晚上吃完晚饭之后在镇海校园里参观 ...
- 【CF453D】 Little Pony and Elements of Harmony(FWT)
题面 传送门 设\(a\)的递推公式为 \[a_i=\sum_ja_jb[count(i\oplus j)]\] 其中\(\oplus\)为异或,\(count(i)\)表示\(i\)的二进制中\(1 ...
- php中递归查找父级名称
/** * 获取所属公司 * @param array 列表 * @param $id 上级ID * @return array */ private static function get_top_ ...
- [Swift]字符串根据索引获取指定字符,依据ASCII实现字符和整数的相互转换
ASCII(American Standard Code for Information Interchange,美国信息交换标准代码)是基于拉丁字母的一套电脑编码系统,主要用于显示现代英语和其他西欧 ...
- python 绘制抛物线
%matplotlib inlineimport matplotlib.pyplot as plt import numpy as npx = range(100) y = [val**2 for v ...
- css3中的translate,transform,transition的区别
translate:移动,transform的一个方法 通过 translate() 方法,元素从其当前位置移动,根据给定的 left(x 坐标) 和 top(y 坐标) ...
- POJ1591 M*A*S*H (JAVA)
这水题,真的坑 测试数据最后有空行,如果用sc.hasNextLine()判断,会RE 要改为sc.hasNext() 搞了我一上午,烦死 import java.util.*; public cla ...