题意简述
将n个1和m个0组成字符串,使1的个数始终大于0的个数
求方案数
题解思路
预处理阶乘和阶乘逆元
最后答案为C(n + m, m) - C(n + m, m - 1)
代码
#include <cstdio>
using namespace std;
typedef long long ll;
const int mod = 20100403;
int n, m, x, ans;
int fac[2000010], inv[2000010];
int ksm(int x, int y, int s = 1)
{
for (; y; y >>= 1, x = (ll)x * x % mod)
if (y & 1)
s = (ll)s * x % mod;
return s;
}
int C(int x, int y)
{
return ((ll)fac[x] * inv[y] % mod) * inv[x - y] % mod;
}
int main()
{
scanf("%d%d", &n, &m);
x = n + m;
fac[0] = 1;
for (register int i = 1; i <= x; ++i)
fac[i] = (ll)fac[i - 1] * i % mod;
inv[x] = ksm(fac[x], mod - 2);
for (register int i = x - 1; i; --i)
inv[i] = (ll)inv[i + 1] * (i + 1) % mod;
ans = (((ll)C(n + m, m) - C(n + m, m - 1)) % mod + mod) % mod;
printf("%d
", ans);
}