首页 技术 正文
技术 2022年11月19日
0 收藏 955 点赞 3,363 浏览 1271 个字

http://www.lydsy.com/JudgeOnline/problem.php?id=4008 (题目链接)

题意

  给出n个技能,每个技能按顺序有p[i]的可能性释放,可以造成d[i]的伤害。每一轮游戏只能发动一个技能,问r轮游戏期望造成的伤害。

Solution

  刚了半个下午的dp,然而Wa了又调,调了又Wa,发现整个dp都是萎的,然后删了重写。。。无奈,看了题解。

  http://blog.csdn.net/vmurder/article/details/46461649

  get了求期望的新姿势。。。$${ f_{i,j} = f_{i-1,j} × (1 – p_{i-1})^j + f_{i-1,j+1}×(1-(1-p_{i-1})^{j+1})}$$

  其中${f_{i-1,j} × (1 – p_{i-1})^j}$表示第${i-1}$张技能牌被所有机会跳过。

  其中${f_{i-1,j+1}×(1-(1-p_{i-1})^{j+1})}$表示第${i-1}$张技能牌被其中一个机会选中,逆向思考,即1-被所有机会跳过的概率。

  那么第${i}$张技能牌发动的概率是多少呢?显然:${P_i=\sum_{j=1}^rf_{i,j}×(1-(1-p_{i})^j)}$

代码

// bzoj4008
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define inf 1<<30
#define Pi acos(-1.0)
#define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
using namespace std;const int maxn=500;
int d[maxn],n,r;
double p[maxn],f[maxn][maxn];double power(double a,int b) {
double res=1;
while (b) {
if (b&1) res*=a;
b>>=1;a*=a;
}
return res;
}
int main() {
int T;scanf("%d",&T);
while (T--) {
memset(f,0,sizeof(f));
scanf("%d%d",&n,&r);
for (int i=1;i<=n;i++) scanf("%lf%d",&p[i],&d[i]);
f[0][r]=1;double ans=0;
for (int i=1;i<=n;i++)
for (int j=1;j<=r;j++) {
f[i][j]=f[i-1][j]*power(1-p[i-1],j)+f[i-1][j+1]*(1-power(1-p[i-1],j+1));
ans+=f[i][j]*(1-power(1-p[i],j))*d[i];
}
printf("%.10lf\n",ans);
}
return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,031
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,860