[Luogu 2265]路边的水沟

时间:2023-03-09 07:38:50
[Luogu 2265]路边的水沟

Description

LYQ市有一个巨大的水沟网络,可以近似看成一个n*m的矩形网格,网格的每个格点都安装了闸门,我们将从水沟网络右下角的闸门到左上角的闸门的一条路径称为水流。

现给定水沟网的长和宽,求该水沟网中所有只包含向左和向上移动的水流数量。

Input

输入共1行,包含两个整数n和m。

Output

输出一个数字ans,即水流的数量。由于答案可能很大,请输出答案对1000000007取模的结果。

Sample Input

3 5

Sample Output

56

Hint

对于30%的数据,1 ≤ m,n ≤ 10。

对于50%的数据,1 ≤ m,n ≤ 1,000。

对于80%的数据,1 ≤ m,n ≤ 50,000。

对于100%的数据,1 ≤ m,n ≤ 1,000,000。

题解

乘法逆元模板...

 //It is made by Awson on 2017.11.2
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Abs(a) ((a) < 0 ? (-(a)) : (a))
using namespace std;
const int N = ;
const int MOD = ; int n, m;
int A[(N<<)+]; void work() {
scanf("%d%d", &n, &m);
int ans = ; A[] = ;
for (int i = ; i <= m; i++) A[i] = -(LL)(MOD/i)*A[MOD%i]%MOD;
for (int i = n+; i <= m+n; i++) ans = (LL)ans*i%MOD;
for (int i = ; i <= m; i++) ans = (LL)ans*A[i]%MOD;
printf("%d\n", (ans+MOD)%MOD);
}
int main() {
work();
return ;
}