題意 "題目鏈接" Sol $30 \%$dp: $f[i][j]$表示放了$i$個$1$和$j$個$0$的不合法方案 ...
題意
Sol
\(30 \%\)dp:
\(f[i][j]\)表示放了\(i\)個\(1\)和\(j\)個\(0\)的不合法方案
f[0][0] = 1;
cin >> N >> M;
for(int i = 1; i <= N; i++) {
f[i][0] = 1;
for(int j = 1; j <= i; j++) {
f[i][j] = add(f[i - 1][j], f[i][j - 1]);
}
}
cout << f[N][M];
我們可以把\(1\)看做是\((+1, +1)\), \(0\)看做是\((+1, -1)\),根據折射原理,不合法的方案為\(C_{n+m}^{n+1}\)
詳細點的題解可以看這裡
#include<bits/stdc++.h>
#include<algorithm>
#define LL long long
#define ull long long
using namespace std;
const int MAXN = 2e6 + 10, mod = 20100403;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int add(int x, int y) {
if(x + y < 0) return x + y + mod;
return x + y >= mod ? x + y - mod : x + y;
}
int mul(int x, int y) {
return 1ll * x * y % mod;
}
int fp(int a, int p) {
int base = 1;
while(p) {
if(p & 1) base = mul(base, a);
a = mul(a, a); p >>= 1;
}
return base;
}
int N, M, fac[MAXN], ifac[MAXN];
int C(int N, int M) {
return mul(mul(fac[N], ifac[M]), ifac[N - M]);
}
main() {
cin >> N >> M; int Lim = N + M;
fac[0] = 1;
for(int i = 1; i <= Lim; i++) fac[i] = mul(i, fac[i - 1]);
ifac[Lim] = fp(fac[Lim], mod - 2);
for(int i = Lim; i >= 1; i--) ifac[i - 1] = mul(ifac[i], i);
printf("%d\n", (C(N + M, N) - C(N + M, N + 1) + mod) % mod);
return 0;
}