题意
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#include #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;}