AtCoder Grand Contest 019 F-yes or no
阿新 • • 發佈:2019-03-13
include main out cout ogr program template 需要 contest ,組合數搞搞就好了
AtCoder Grand Contest 019 F-yes or no
解題思路:
考慮一個貪心策略,假設當前還有 \(x\) 道 \(\text{yes}\) 和 \(y\) 道 \(\text{no}\) ,那麽一定猜較大者,如果 \(x=y\) 就相當於隨便猜一個,把 \((x, y)\) 用坐標表示,把所有在這種決策下猜對的邊用藍色表示,走過這樣一條邊就相當於有 \(1\) 的貢獻,然後會發現從 \((0,0)\) 到 \((n,m)\) 的所有路徑經過的藍色的邊的數量都是相同的 \(\max(n,m)\) 條,也就是說只需要考慮每次在 \((x=y)\) 時的決策的貢獻之和就好了。
這個東西就是經過這個點的路徑方案數乘上 \(\dfrac{1}{2}\)
a/*program by mangoyang*/ #pragma GCC optimize("Ofast", "inline") #include <bits/stdc++.h> #define inf (0x7f7f7f7f) #define Max(a, b) ((a) > (b) ? (a) : (b)) #define Min(a, b) ((a) < (b) ? (a) : (b)) typedef long long ll; using namespace std; template <class T> inline void read(T &x){ int f = 0, ch = 0; x = 0; for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1; for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48; if(f) x = -x; } const int N = 1000005, mod = 998244353; ll js[1000005], inv[1000005], n, m, ans; inline ll Pow(ll a, ll b){ ll ans = 1; for(; b; b >>= 1, a = a * a % mod) if(b & 1) ans = ans * a % mod; return ans; } inline ll C(ll x, ll y){ return js[x] * inv[y] % mod * inv[x-y] % mod; } int main(){ read(n), read(m); if(n > m) swap(n, m); js[0] = inv[0] = 1; for(int i = 1; i < N; i++) js[i] = 1ll * js[i-1] * i % mod, inv[i] = Pow(js[i], mod - 2); for(int i = 1; i <= n; i++) (ans += C(n + m - 2 * i, m - i) * C(2 * i, i) % mod) %= mod; cout << ((m + ans * inv[2] % mod * Pow(C(n + m, n), mod - 2) % mod) % mod + mod) % mod << endl; }
AtCoder Grand Contest 019 F-yes or no