首页 > 其他分享 >题解 ABC333F【Bomb Game 2】

题解 ABC333F【Bomb Game 2】

时间:2023-12-17 22:24:26浏览次数:26  
标签:tmp return int 题解 Game Modint operator Bomb friend

来个可能有点麻烦但不用动脑子的暴力做法。

直接设 \(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

相关文章

  • CF1906K Deck-Building Game记录
    CF1906KDeck-BuildingGame题目链接:https://codeforces.com/problemset/problem/1906/K题意有大小为$n$的多重集$A$。求找到两个不相交子集,使它们各自的异或和相等的方案数。很容易将其转换为求如下值:$$\sum_{S\subsetA}2^{|S|}\cdot[\oplus_{x\inS}x=0]$$......
  • 链表面试题解析
    链表面试题解析1.删除链表中=val的所有节点/***Definitionforsingly-linkedlist.*publicclassListNode{*intval;*ListNodenext;*ListNode(){}*ListNode(intval){this.val=val;}*ListNode(intval,ListNodenext){......
  • BZOJ4403 序列统计 题解
    题目传送门前置知识排列组合|卢卡斯定理解法记\(m=r-l+1,0\lek\len-1\),枚举长度\(i\),等价于求\(\sum\limits_{j=1}^{m}x_j=i\)的非负整数解的数量。接着推式子就行。\(\begin{aligned}\sum\limits_{i=1}^{n}\dbinom{m+i-1}{i}\end{aligned}\)\(\begin{aligned......
  • 【电子公文系统】常见问题解答
    Q:如何在电子公文系统中创建新文档?A:登录系统后,点击“新建文档”按钮,选择相应的文档模板开始编辑。编辑完成后,可以选择保存草稿或提交审批。Q:我忘记了我的登录密码,应该怎么办?A:在登录界面点击“忘记密码”链接,根据提示输入你的电子邮箱或电话号码以接收重置密码的......
  • 2023ISCTF的fry题解及进阶格式化利用
    这题是一个比较好的进阶格式化利用。就是有点繁琐。先惯例checksec一下心脏骤停hhh。没事先分析一下Main函数int__cdeclmain(intargc,constchar**argv,constchar**envp){init(argc,argv,envp);puts("WelcometoISCTF~~~~~~~~~~~~~~~~");puts("Doyouwantto......
  • [Ynoi2004] rpmtdq 题解
    人生第一发\(Ynoi\)的题,写一篇题解庆祝一下传送门我们可以发现,对于二元组\((x,y)\),若存在一个\(dist(i,j)\ledist(x,y),x<i<j<y\)那么答案肯定不是二元组\((x,y)\)我们可以考虑把这些肯定不是的点剔除掉考虑怎么找,我们可以先点分治,求出每个点......
  • AT_abc333_e [ABC333E] Takahashi Quest 题解
    AT_abc333_e[ABC333E]TakahashiQuest题解思路解析可以发现一瓶药水无论什么时候拿被使用掉的时间都是不会变的,所以如果我们想让一瓶药水再背包里待得时间尽可能的短就要让它尽可能的被晚拿起来,于是我们就可以想到使用栈存下每一瓶同类的药水分别出现的时间,此时每遇到一只怪......
  • 2022年RHCE认证考题解析最新版—RH294环境【转】
    由于本人10.17已成功考过CSA,经过两周所学的ansible并结合题库整理出来的CE解析版我也是11月月底就要考了,不过这套解析也是可以满足今年的redhat8题库文中可能涉及一些命令的参数解释,如有不懂的伙伴可参考我的笔记Ansibleps:一切模板似的题库考试,都需要经过大脑的理解方可顺利上......
  • VMware workstation中安装的centos虚拟机ip自动获取可以上网,设置静态ip不能上网问题解
    一、需求   linux中我们会设置hosts文件,这会涉及ip和域名的设置,但是如果虚拟机自动获取ip地址的话,这就意味着之前设置的hosts文件需要重新修改,所以我们需要设置虚拟机为静态ip地址。二、故障现象   我linux虚拟机最开始是自动获取的ip地址,用的nat模式,是可以上网的,......
  • pygame安装问题
    pygame的安装问题(1)python-mpipinstall--upgradepip(2)pipinstallpygame(3)更换下载网站,且赋予信任pipinstallpygame-ihttp://pypi.douban.com/simple--trusted-hostpypi.douban.com(4)python-mpipinstall-Upygame--user(5)python-mpipinstall-Upy......