链接
https://ac.nowcoder.com/acm/contest/8688/D
题意
有 血量, 有 血量。
每个回合 会发起一次攻击,每次攻击造成 伤害,有 概率击中 , 概率击中自己。
当有一个人血量少于等于 时,游戏结束。
求回合数的期望。
思路
记 为 剩 血量 剩 血量的回合数期望。
当 或 时,期望必为 。
倒推, 为答案。
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| #include <bits/stdc++.h> #define SZ(x) (int)(x).size() #define ALL(x) (x).begin(),(x).end() #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second using namespace std; typedef double DB; typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> PII; typedef vector<int> VI; typedef vector<PII> VPII;
const int N=3005; DB dp[N][N]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin>>T; while(T--) { int hp1,hp2,w; DB p; cin>>hp1>>hp2>>w>>p; for(int i=1;i<=hp1;i++) { for(int j=1;j<=hp2;j++) { dp[i][j]=(dp[max(0,i-w)][j]+1)*(1-p)+(dp[i][max(0,j-w)]+1)*p; } } cout<<fixed<<setprecision(6)<<dp[hp1][hp2]<<'\n'; } return 0; }
|
未找到相关的 Issues 进行评论
请联系 @c4Lnn 初始化创建