#include<bits/stdc++.h> #define endl "\n" #define int long long
usingnamespace std; typedef pair<int, int> pii; constint N = 1e5 + 5; int n, m; int f[N][7]; //第i秒时在位置j int dx[] = {-1, 0, 1};
signedmain(){ ios::sync_with_stdio (0);cin.tie(0);cout.tie(0); memset (f, 0, sizeof f); cin >> n; for (int i = 0; i < n; i++) { int ti, xi, ai; cin >> ti >> xi >> ai; f[ti][xi] = ai; m = max (m, ti); } //cout << "m=" << m << endl;
for (int t = m-1; t >= 0; t--) { f[t][0] += max (f[t+1][0], f[t+1][1]); for (int x = 1; x < 4; x++) { f[t][x] += max (f[t+1][x], max (f[t+1][x+1], f[t+1][x-1])); } f[t][4] += max (f[t+1][4], f[t+1][3]); cout << endl; } cout << f[0][0] << endl; }
E - Throwing the Die
题意:n 轮游戏,每次可以丢一枚骰子,每次丢完可以选择结束游戏或者继续。 结束游戏时的分数为最终得分,如果一直按照最优策略来投,求 n 轮游戏的期望得分。
usingnamespace std; using i64 = longlong; constint P = 998244353, N = 3e6 + 5; int R, G, B, K;
using i64 = longlong; // assume -P <= x < 2P intnorm(int x){ if (x < 0) { x += P; } if (x >= P) { x -= P; } return x; } template<class T> T power(T a, i64 b){ T res = 1; for (; b; b /= 2, a *= a) { if (b % 2) { res *= a; } } return res; }
structZ { int x; Z(int x = 0) : x(norm(x)) {} Z(i64 x) : x(norm(x % P)) {} intval()const{ return x; } Z operator-() const { returnZ(norm(P - x)); } Z inv()const{ assert(x != 0); returnpower(*this, P - 2); } Z &operator*=(const Z &rhs) { x = i64(x) * rhs.x % P; return *this; } Z &operator+=(const Z &rhs) { x = norm(x + rhs.x); return *this; } Z &operator-=(const Z &rhs) { x = norm(x - rhs.x); return *this; } Z &operator/=(const Z &rhs) { return *this *= rhs.inv(); } friend Z operator*(const Z &lhs, const Z &rhs) { Z res = lhs; res *= rhs; return res; } friend Z operator+(const Z &lhs, const Z &rhs) { Z res = lhs; res += rhs; return res; } friend Z operator-(const Z &lhs, const Z &rhs) { Z res = lhs; res -= rhs; return res; } friend Z operator/(const Z &lhs, const Z &rhs) { Z res = lhs; res /= rhs; return res; } friend std::istream &operator>>(std::istream &is, Z &a) { i64 v; is >> v; a = Z(v); return is; } friend std::ostream &operator<<(std::ostream &os, const Z &a) { return os << a.val(); } };
Z fac[N], inv[N]; Z C(int x,int y){ return fac[x] * inv[y] * inv[x-y]; }
signedmain(){ cin >> R >> G >> B >> K; int N = R + G + B;
fac[0] = 1; for (int i = 1; i <= N; i++) fac[i] = fac[i-1] * i; inv[N] = fac[N].inv(); for (int i = N; i; i--) inv[i-1] = inv[i] * i;
Z ans = C(G+B, G) * C(G, K) * C(B+R, R-K); cout << ans; }