标签:不用 art targe tar turn problem typedef 依次 lan
n = x2 - x1 + y2 - y1
m = x2 - x1
C(n, m) = n! / (m! * (n - m)!)
C(n, m) = n! * infact(m) * infact(n-m)
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
ll n, m, k, ans = 1;
ll fact[N], infact[N]; //阶乘求余后的结果,阶乘的逆元求余后的结果
struct Node
{
ll x, y;
}g[N];
ll qpow(ll a, ll x, ll p)
{
ll res = 1;
while(x)
{
if(x & 1) res = res * a % p;
a = a * a % p;
x >>= 1;
}
return res;
}
int main()
{
cin >> n >> m >> k;
g[0].x = 1, g[0].y = 1;
for(ll i = 1; i <= k; i++)
cin >> g[i].x >> g[i].y;
++ k;
g[k].x = n, g[k].y = m;
//预处理阶乘的余数与阶乘逆元的余数
fact[0] = 1, infact[0] = 1;
for(ll i = 1; i <= N - 5; i++)
{
fact[i] = i * fact[i-1] % mod;
infact[i] = qpow(fact[i], mod - 2, mod);
}
for(ll i = 1; i <= k; i++)
{
ll dx = abs(g[i].x - g[i-1].x);
ll dy = abs(g[i].y - g[i-1].y);
ll sum = dx + dy;
ans = ans * fact[sum] % mod * infact[dx] % mod * infact[sum - dx] % mod; //C(sum, dx) = (sum! / dx! * ( (sum - dx)!) )
}
cout << ans << endl;
return 0;
}
标签:不用 art targe tar turn problem typedef 依次 lan
原文地址:https://www.cnblogs.com/K2MnO4/p/14873291.html