传送门:点击打开链接
题意:只能往右下走,一次可以走很远。求从(1,1)走到(n,m)的步骤数
思路:枚举走的步数,假如为x
那么,对于行,我要从1通过x步走到n
对于列,我要从1通过x步走到m
这两个操作是独立的,所以可以乘起来
那么现在题目就变成了,求从1到n通过x步的方案数,其实就是把n-1个一样的小球放到x个不一样的箱子中,箱子不能留空的方案数,也就是一个经典的排列组合问题了
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#define fuck(x) cout<<"["<<x<<"]";
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w+",stdout);
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MX = 1e5 + 5;
const int mod = 1e9 + 7;
LL F[MX], invF[MX];
LL power(LL a, LL b) {
LL ret = 1;
while(b) {
if(b & 1) ret = (ret * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return ret;
}
void init() {
F[0] = 1;
for(int i = 1; i < MX; i++) {
F[i] = (F[i - 1] * i) % mod;
}
invF[MX - 1] = power(F[MX - 1], mod - 2);
for(int i = MX - 2; i >= 0; i--) {
invF[i] = invF[i + 1] * (i + 1) % mod;
}
}
LL C(int n, int m) {
if(n < 0 || m < 0 || m > n) return 0;
if(m == 0 || m == n) return 1;
return F[n] * invF[n - m] % mod * invF[m] % mod;
}
LL f(int x, int y) {
return C(y - 2, x - 1);
}
int main() {
init();
int n, m; //FIN;
while(~scanf("%d%d", &n, &m)) {
LL ans = 0;
for(int l = 1; l <= min(n - 1, m - 1); l++) {
ans += f(l, n) * f(l, m) % mod;
ans %= mod;
}
printf("%I64d\n", ans);
}
return 0;
}