来个可能有点麻烦但不用动脑子的暴力做法。
直接设 \(f_{i,j}\) 表示有 \(i\) 个人时,第 \(j\) 个人幸存的概率。
显然有 \(f_{1,1}=1\)。
对于 \(i > 1\),分类讨论容易得到:
\[f_{i,j}= \begin{cases} \frac{f_{i,n}}{2},&j = 1\\ \frac{f_{i-1,j-1}+f_{i,j-1}}{2},&1 < j\le i\\ \end{cases} \]但是转移成环,无法通过正常方式转移。我们设 \(f_{i,1}=x\),然后根据 \(f_{i,j}=\frac{f_{i-1,j-1}+f_{i,j-1}}{2}\) 将所有 \(f_{i,j}\) 用 \(x\) 和常数表示出来,最后根据 \(f_{i,1}=\frac{f_{i,n}}{2}\) 即可解得 \(x\) 的具体值,再重新把所有 \(f_{i,j}\) 算出来即可。
时间复杂度 \(O(n^2)\)。
// Problem: F - Bomb Game 2
// Contest: AtCoder - Toyota Programming Contest 2023#8(AtCoder Beginner Contest 333)
// URL: https://atcoder.jp/contests/abc333/tasks/abc333_f
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
//By: OIer rui_er
#include <bits/stdc++.h>
#define rep(x, y, z) for(int x = (y); x <= (z); ++x)
#define per(x, y, z) for(int x = (y); x >= (z); --x)
#define debug(format...) fprintf(stderr, format)
#define fileIO(s) do {freopen(s".in", "r", stdin); freopen(s".out", "w", stdout);} while(false)
#define endl '\n'
using namespace std;
typedef long long ll;
mt19937 rnd(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
int randint(int L, int R) {
uniform_int_distribution<int> dist(L, R);
return dist(rnd);
}
template<typename T> void chkmin(T& x, T y) {if(x > y) x = y;}
template<typename T> void chkmax(T& x, T y) {if(x < y) x = y;}
template<int mod>
inline unsigned int down(unsigned int x) {
return x >= mod ? x - mod : x;
}
template<int mod>
struct Modint {
unsigned int x;
Modint() = default;
Modint(unsigned int x) : x(x) {}
friend istream& operator>>(istream& in, Modint& a) {return in >> a.x;}
friend ostream& operator<<(ostream& out, Modint a) {return out << a.x;}
friend Modint operator+(Modint a, Modint b) {return down<mod>(a.x + b.x);}
friend Modint operator-(Modint a, Modint b) {return down<mod>(a.x - b.x + mod);}
friend Modint operator*(Modint a, Modint b) {return 1ULL * a.x * b.x % mod;}
friend Modint operator/(Modint a, Modint b) {return a * ~b;}
friend Modint operator^(Modint a, int b) {Modint ans = 1; for(; b; b >>= 1, a *= a) if(b & 1) ans *= a; return ans;}
friend Modint operator~(Modint a) {return a ^ (mod - 2);}
friend Modint operator-(Modint a) {return down<mod>(mod - a.x);}
friend Modint& operator+=(Modint& a, Modint b) {return a = a + b;}
friend Modint& operator-=(Modint& a, Modint b) {return a = a - b;}
friend Modint& operator*=(Modint& a, Modint b) {return a = a * b;}
friend Modint& operator/=(Modint& a, Modint b) {return a = a / b;}
friend Modint& operator^=(Modint& a, int b) {return a = a ^ b;}
friend Modint& operator++(Modint& a) {return a += 1;}
friend Modint operator++(Modint& a, int) {Modint x = a; a += 1; return x;}
friend Modint& operator--(Modint& a) {return a -= 1;}
friend Modint operator--(Modint& a, int) {Modint x = a; a -= 1; return x;}
friend bool operator==(Modint a, Modint b) {return a.x == b.x;}
friend bool operator!=(Modint a, Modint b) {return !(a == b);}
};
typedef Modint<998244353> mint;
const int N = 3e3 + 5, inv2 = 998244354 / 2;
int n;
mint dp[N][N];
struct Complex {
mint real, imag;
Complex(mint r = 0, mint i = 0) : real(r), imag(i) {}
friend istream& operator>>(istream& in, Complex& a) {return in >> a.real >> a.imag;}
friend ostream& operator<<(ostream& out, Complex a) {return out << a.real << " " << a.imag;}
friend Complex operator+(Complex a, Complex b) {return Complex(a.real + b.real, a.imag + b.imag);}
friend Complex& operator+=(Complex& a, Complex b) {return a = a + b;}
friend Complex operator*(Complex a, mint b) {return Complex(a.real * b, a.imag * b);}
}tmp[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
dp[1][1] = 1;
rep(i, 2, n) {
tmp[1] = Complex(0, 1);
rep(j, 2, i) tmp[j] = (dp[i - 1][j - 1] + tmp[j - 1]) * inv2;
mint mul = tmp[i].real / (2 - tmp[i].imag);
rep(j, 1, i) dp[i][j] = tmp[j].real + tmp[j].imag * mul;
}
rep(j, 1, n) cout << dp[n][j] << " \n"[j == n];
return 0;
}
标签:tmp,return,int,题解,Game,Modint,operator,Bomb,friend
From: https://www.cnblogs.com/ruierqwq/p/abc333f.html