Codeforces E. Qwerty78 Trip 【组合数学】

n*m的格子，其中有一个格子是坏的，问你从(1, 1) - (n, m)有多少种走法。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <stack>
#define CLR(a, b) memset(a, b, sizeof(a))
#define PI acos(-1.0)
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 2 * 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
void add(LL &x, LL y) { x += y; x %= MOD; }
LL pow_mod(LL a, int n) {
LL ans = 1;
while(n) {
if(n & 1) {
ans = ans * a % MOD;
}
a = a * a % MOD;
n >>= 1;
}
return ans;
}
LL f[MAXN];
LL C(int n, int m) {
return f[n] * pow_mod(f[n-m], MOD-2) % MOD * pow_mod(f[m], MOD-2) % MOD;
}
int n, m;
int main()
{
f[0] = 1LL;
for(int i = 1; i <= 200000; i++) {
f[i] = f[i-1] * i % MOD;
}
int t; scanf("%d", &t);
while(t--) {
scanf("%d%d", &n, &m);
int x, y; scanf("%d%d", &x, &y);
if(x == 1 && y == 1) {
printf("0\n");
continue;
}
printf("%lld\n", (C(n+m-2, m-1) - C(n+m-(x-1)-(y-1)-2, m-(y-1)-1) * C(x+y-2, y-1) % MOD + MOD) % MOD);
}
return 0;
}

Codeforces Round#466 E. Cashback

2018-02-24 22:11:50

[最短路 主席树 Hash] Codeforces 464E #265 (Div. 1) E. The Classic Problem

2017-03-17 20:53:14

Codeforces Round #467 (Div. 1) E：Iqea（点分治）

2018-03-05 16:49:38

Codeforces Round #472 E. Wardrobe 至少有一个物品没用的01背包

2018-03-26 02:09:07

CodeForces - 999E

2018-06-23 16:45:49

[Codeforces954E]Water Taps

2018-03-22 19:57:19

Codeforces Round #456 (Div. 2): E. Prime Gift（折半枚举）

2018-01-06 15:03:53

Codeforces ~ 1003E ~ Tree Constructing （贪心）

2018-07-06 00:34:41

codeforces 999E Reachability from the Capital

2018-06-22 13:04:47

CodeForces 663E - Binary Table FWT

2017-01-10 14:10:21