题目大意:

有n条路,选每条路的概率相等,初始能力值为f,每条路通过的难度值为ci,当能力值大于某条路A的难度值b时,能够成功逃离,花费时间ti,小于等于时,不能逃离,天数加一天,但能力值增加b.

给定初始的能力值,求成功逃离的期望。

分析:

概率dp做的少,感觉不是很简单。

设dp[j]表示能力值为j时,逃离的期望值。

对于每条路i,当j>c[i]时,成功逃离+(ti[i]*p),否则加(+1+dp[j+c[j]])*p;

从后往前递推,求出dp[f]。

精度卡的好严,看看下面2个代码就行了

WA的代码

 #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#define INF 10000000
using namespace std;
int main()
{
int n,f;
double dp[];
int c[],t[];
while(scanf("%d %d",&n,&f)!=EOF)
{
int sum=,Max=-INF;
for(int i=; i<n; i++)
{
scanf("%d",&c[i]);
Max=max(Max,c[i]);
int tt=(int)((1.0+sqrt(5.0))/2.0*c[i]*c[i]);
t[i]=tt;
sum+=t[i];
}
double p=1.0/n;
for(int i=Max+; i<=*Max; i++)
dp[i]=(double)sum*p;
for(int j=Max; j>=f; j--)
{
double tem=0.0;
for(int i=; i<n; i++)
{
if(c[i]<j)
tem+=t[i]*p;
else
tem+=(+dp[j+c[i]])*p;
}
dp[j]=tem;
}
printf("%.3lf\n",dp[f]);
}
return ;
}

AC 代码

 #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#define INF 10000000
using namespace std;
int main()
{
int n,f;
double dp[];
int c[],t[];
while(scanf("%d %d",&n,&f)!=EOF)
{
double sum=;
int Max=-INF;
for(int i=;i<n;i++)
{
scanf("%d",&c[i]);
Max=max(Max,c[i]);
int tt=(int)((1.0+sqrt(5.0))/2.0*c[i]*c[i]);
t[i]=tt;
sum+=t[i];
}
double p=1.0/n;
for(int i=Max+;i<=*Max;i++)
dp[i]=sum*p;
for(int j=Max;j>=f;j--)
{
double tem=0.0;
for(int i=;i<n;i++)
{
if(c[i]<j)
tem+=t[i]*p;
else
tem+=(+dp[j+c[i]])*p;
}
dp[j]=tem;
}
printf("%.3lf\n",dp[f]);
}
return ;
}

ZOJ Problem Set - 3640 Help Me Escape的更多相关文章

  1. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  2. ZOJ Problem Set - 1025解题报告

    ZOJ Problem Set - 1025 题目分类:基础题 原题地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=10 ...

  3. ZOJ Problem Set - 3829Known Notation(贪心)

    ZOJ Problem Set - 3829Known Notation(贪心) 题目链接 题目大意:给你一个后缀表达式(仅仅有数字和符号),可是这个后缀表达式的空格不幸丢失,如今给你一个这种后缀表达 ...

  4. ZOJ Problem Set - 2563 Long Dominoes 【如压力dp】

    称号:ZOJ Problem Set - 2563 Long Dominoes 题意:给出1*3的小矩形.求覆盖m*n的矩阵的最多的不同的方法数? 分析:有一道题目是1 * 2的.比較火.链接:这里 ...

  5. ZOJ Problem Set - 3593 拓展欧几里得 数学

    ZOJ Problem Set - 3593 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3593 One Person ...

  6. ZOJ Problem Set - 2297 Survival 【状压dp】

    题目:ZOJ Problem Set - 2297 Survival 题意:给出一些怪,有两个值,打他花费的血和能够添加的血,然后有一个boss,必须把小怪全部都打死之后才干打boss,血量小于0会死 ...

  7. ZOJ Problem Set - 3820 Building Fire Stations 【树的直径 + 操作 】

    题目:problemId=5374" target="_blank">ZOJ Problem Set - 3820 Building Fire Stations 题 ...

  8. ZOJ Problem Set - 3229 Shoot the Bullet 【有上下界网络流+流量输出】

    题目:problemId=3442" target="_blank">ZOJ Problem Set - 3229 Shoot the Bullet 分类:有源有汇 ...

  9. ZOJ Problem Set - 3822Domination(DP)

    ZOJ Problem Set - 3822Domination(DP) problemCode=3822">题目链接 题目大意: 给你一个n * m的棋盘,每天都在棋盘上面放一颗棋子 ...

随机推荐

  1. 投资统计查询sql

    select COUNT(*) from YYD_Users_RegInfo where regTime between '2016-07-11 00:00:00' and '2016-07-11 2 ...

  2. windows系统常见端口和木马默认使用端口

    dos命令netstat比较好用,能比较全的看到自己开放的端口及状态一般我用netstat -a端口:0服务:Reserved说明:通常用于分析操作系统.这一方法能够工作是因为在一些系统中“0”是无效 ...

  3. bzoj 2330: [SCOI2011]糖果

    #include<cstdio> #include<iostream> using namespace std; ],next[],u[],v[],h,t,a[]; ],f[] ...

  4. HDU 4906 Our happy ending(2014 Multi-University Training Contest 4)

    题意:构造出n个数 这n个数取值范围0-L,这n个数中存在取一些数之和等于k,则这样称为一种方法.给定n,k,L,求方案数. 思路:装压 每位 第1为表示这种方案能不能构成1(1表示能0表示不能)   ...

  5. C++之函数fgetc和fputc、fgets和fputs、fread和fwrite、fscanf和fprintf用法小结

    #include <iostream> #include <cstdio> #include <cstdlib> using namespace std; int ...

  6. c# MVC中 @Styles.Render索引超出下标

    @Styles.Render( "~/Content/bootstrap/css", "~/Content/mycss") 提示索引超出下标 后来发现市boot ...

  7. const的全面理解

    const关键字用来作甚?const是一个类型修饰符.常见的类型修饰符有哪些? short long unsigned signed static autoextern register 定义一个变量 ...

  8. JAVA学习1

    以前学过JAVA,但是长时间不用又给忘了,趁着还有时间回顾一下. 一切皆是对象.

  9. JavaScript中Date的一些细节

    对于开发人员来说,Date有时候或许会很重要,我们可以通过new Date()来创建一个日期对象.例如: var start = new Date(), //获取当前时间 today = new Da ...

  10. idea修改jsp后不会自动编译和替换(转)

    使用IntelliJ IDEA开发JavaWeb项目时,修改了JSP后刷新浏览器无法及时显示修改后的页面? 解决办法:tomcat配置中,On frame deactivation属性选择Update ...