版本比较
题解-gym102978C Count Min Ratio
正文
增加 12 行删除 12 行
50 行未改动5152535455555657585914 行未改动7475767778787980818234 行未改动11711811912012112212112212312412512612712812912913013113213354 行未改动1881891901911921921931941951961971981992002012012022032042052062062072082092102 行未改动21321421521621721721821922022122222322422422522622722827 行未改动25625725825926026026126226326426526526650 行未改动
其实我们算的就是从 $(0, 0)$ 到 $(H + 1, W)$ ,因此 $g(W, H, A, P) - Ag(W - 1, H+1, A, P) = \binom{H+W+1}{W}$。结果和 $P$ 无关!
因此 $g(W,H,A,P) = \sum\limits_{i = 0}^{W} \binom{H+W+1}{i} A^{W-i}$
--------------
接下来就很好做了:要算的是 $\sum\limits_{A = 1}^{\frac{R}{B}} (R-AB+1) \sum\limits_{i = 0}^{B} \binom{B+R+1}{i} A^{B-i}$。
14 行未改动using namespace std;const int mod = 998244353, G = 3, iG = (mod + 1) / G, N = 2.1e6 + 7, inv2 = (mod + 1) / 2;#define add(a, b) (a + b >= mod ? a + b - mod : a + b)#define dec(a, b) (a < b ? a - b + mod : a - b)inline ull calc(const ull &x) { inline ull calc(const ull &x) { return x - (__uint128_t(x) * 9920937979283557439ull >> 93) * 998244353;}int qpow(int x, int y = mod - 2) { int res = 1;34 行未改动 void ntt(int op, int t = true) { int n = sz(a); if(t) initrev(n); L(i, 0, n - 1) if(rev[i] < i) swap(a[rev[i]], a[i]); for(int i = 2; i <= n; i <<= 1) for(int j = 0, l = (i >> 1), ch = Lim / i; j < n; j += i) for(int i = 2; i <= n; i <<= 1) for(int j = 0, l = (i >> 1), ch = Lim / i; j < n; j += i) for(int k = j, now = 0; k < j + l; k++) { int pa = a[k], pb = calc((ull) a[k + l] * (op == 1 ? rt[now] : rt[Lim - now])); a[k] = add(pa, pb), a[k + l] = dec(pa, pb), now += ch; } if(op != 1) for(int i = 0, iv = qpow(n); i < n; i++) a[i] = (ll) a[i] * iv % mod; }
friend poly operator * (poly aa, poly bb) { if(!sz(aa) || !sz(bb)) return {}; int lim, all = sz(aa) + sz(bb) - 1; for(lim = 1; lim < all; lim <<= 1);54 行未改动 return res; } poly Deriv() { if(!sz(a)) return poly(); poly res(sz(a) - 1); poly res(sz(a) - 1); L(i, 1, sz(a) - 1) res[i - 1] = (ll) a[i] * i % mod; return res; } poly Ln() { poly g = ((*this).Inv() * (*this).Deriv()).Integ(); return g.rs(sz(a)), g; } poly Exp() { poly res(1), f; poly res(1), f; res[0] = 1; for(int m = 1, pn; m < sz(a); m <<= 1) { pn = min(m << 1, sz(a)), f.rs(pn), res.rs(pn); for(int i = 0; i < pn; i++) f[i] = (*this).v(i); f -= res.Ln(), (f[0] += 1) %= mod, res *= f, res.rs(pn); f -= res.Ln(), (f[0] += 1) %= mod, res *= f, res.rs(pn); } return res.rs(sz(a)), res; } poly pow(int x) {2 行未改动 res = res.Exp(); return res; } poly sqrt() { poly res(1), f; poly res(1), f; res[0] = 1; for(int m = 1, pn; m < sz(a); m <<= 1) { pn = min(m << 1, sz(a)), f.rs(pn); for(int i = 0; i < pn; i++) f[i] = (*this).v(i); f += res * res, f.rs(pn), res.rs(pn), res = f * res.Inv(), res.rs(pn); for(int i = 0; i < pn; i++) res[i] = (ll) res[i] * inv2 % mod; } } return res; } void Rev() { reverse(a.begin(), a.end());27 行未改动 a *= b; L(i, 0, B + 1) a[i] = (ll) a[i] * fac[i] % mod; (a[0] += mod - 1) %= mod; now = 1; L(i, 0, B) L(i, 0, B) (ns += ((R + 1) % mod * a[B - i] % mod + mod - (ll) B * a[B - i + 1]% mod) % mod * now % mod) %= mod, now = (ll) (B + R + 1 - i) % mod * now % mod * inv[i + 1] % mod; cout << ns << "\n"; return 0;} }```