组合数板子
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 5005;
long long fact[N + 5], infact[N + 5];
const long long P = MOD;
long long qpow(long long x, long long y, long long z)
{
long long ret = 1;
for (; y; y /= 2, x = x * x % z)
if (y & 1)
ret = ret * x % z;
return ret;
}
void init()
{
fact[0] = 1;
for (int i = 1; i <= N; i++)
fact[i] = fact[i - 1] * i % P;
infact[N] = qpow(fact[N], P - 2, P);
for (int i = N; i >= 1; --i)
infact[i - 1] = infact[i] * i % P;
}
long long C(int x, int y) { return x >= y && y >= 0 ? fact[x] * infact[y] % P * infact[x - y] % P : 0; }
int main()
{
init();
int x, y;
cin >> x >> y;
cout << C(x, y);
return 0;
}
(个人学习)