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;
}

最新文章

  1. 学习UFT11.5历程(二)
  2. windows网络编程的一些理论
  3. php 自带函数
  4. 使用 Oracle GoldenGate 在 Microsoft SQL Server 和 Oracle Database 之间复制事务
  5. PHP EOF(heredoc)的使用
  6. Android:设置背景图和标题
  7. [SignalR]注册路由
  8. HDU 4791 &amp;amp; ZOJ 3726 Alice&amp;#39;s Print Service (数学 打表)
  9. javascript运行机制详解: 再谈Event Loop(转)
  10. sql server 的osql 使用例子
  11. Centos6.8通过yum安装mysql5.7 centos7.5适用
  12. 原生js获取子元素、给元素增加div
  13. 在mvc中动态加载菜单
  14. C#系列之{流和序列化}
  15. rabbitmq安装错误集
  16. uWSGI listen queue 队列溢出的问题
  17. PowerDesigner导出表到HTML或word(实测有效)
  18. Spring IOC - 控制反转(依赖注入) - 懒加载机制
  19. 内存管理与正则(re)模块
  20. linux 查看在线服务进程

热门文章

  1. CSS3新特性应用之字体排印
  2. js Function()构造函数
  3. ZeroC Ice启用SSL通讯的配置
  4. Newtonsoft.Json 自定义 解析协议
  5. android6.0的坑
  6. JavaSE 之 final 初探
  7. AngularJS HTML DOM&amp; 事件
  8. 由用友NC刷新功能得到启示
  9. linux输入子系统(input subsystem)之按键输入和LED控制
  10. Azure上的几个坑