【期望DP】 ZOJ 3640 Help Me Escape

通道

题意:吸血鬼在一个洞穴遍地的地方,他拥有初始战斗力,如果战斗力大于了洞穴的c值他就能花时间逃出去,否则他的战斗力增加c,然后随机选择下一个要去的洞穴,问他出去所花时间的期望

思路:设dp[v] ,表示当能力值为v的时的期望。所以方程很容易写了,dp[v] = sum{ ti/n }(v直接逃出去) + sum { (1 + dp[v + c[i]])/n }(下一次逃出去) ;对于路i,如果v大于路i的限制,那么就能够用ti逃出去,概率为{1/n}否则只能进入下一天的尝试,所以需要用的时间为dp[v + c[i]] + 1 ,概率为{1/n};

代码:

#include<iostream>
#include<cstdio>
#include<string.h>
#include<math.h>
using namespace std;

#define N 20005
double  dp[N],t;
int c[105],n,f;

double dfs(int v)
{
    int i,j;
    if(dp[v]>0) return  dp[v];
    for(i=0;i<n;i++)
    {
       if(v>c[i])
       {
           dp[v]=dp[v]+int(t*c[i]*c[i])*1.0/n;
       }
       else
       {
          dp[v]=dp[v]+(1+dfs(v+c[i]))*1.0/n;
       }

    }
    return dp[v];
}
int main()
{
    int i,j;
    t=(1.0+sqrt(5.0))/2.0;
    while(~scanf("%d%d",&n,&f))
    {
        memset(dp,0,sizeof(dp));
        for(i=0;i<n;i++)
          scanf("%d",&c[i]);
       printf("%.3lf\n",dfs(f));
    }
    return 0;
}

时间: 2024-10-23 09:31:11

【期望DP】 ZOJ 3640 Help Me Escape的相关文章

概率dp ZOJ 3640

Help Me Escape Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3640 Appoint description:  System Crawler  (2014-10-22) Description Background     If thou doest well, shalt thou not be accepted? an

zoj 3640 Help Me Escape (概率dp 递归求期望)

题目链接 Help Me Escape Time Limit: 2 Seconds      Memory Limit: 32768 KB Background     If thou doest well, shalt thou not be accepted? and if thou doest not well, sin lieth at the door. And unto thee shall be his desire, and thou shalt rule over him.  

ZOJ 3640 Help Me Escape 概率dp

有一个吸血鬼被困了,有n条路可以逃出去,每条路有一个难度c[],他初始的战斗力是f,对于第i条路,若f > c[i]他花t[i]天就能出去,否则,他就停留一天,同时战斗力增加c[i]然后再选一条路走出去,他走每条路的概率是相同的.问他逃出去的天数的期望. 设dp[i]表示在战斗力为i时逃出去的期望值,那么可推出状态方程 dp[i] = 1/n * t[j](c[j] > i),dp[i] = 1/n * (1+dp[ i+c[j] ] )( c[j] <= i). 需要注意的是终态的确定

ZOJ 3640 Help Me Escape(概率dp+记忆化)

Background     If thou doest well, shalt thou not be accepted? and if thou doest not well, sin lieth at the door. And unto thee shall be his desire, and thou shalt rule over him. And Cain talked with Abel his brother: and it came to pass, when they w

zoj 3640 Help Me Escape(期望)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4808 被这道题坑惨了. 有一个吸血鬼被困了,有n条路可以逃出去,每条路有一个难度c[],他初始的战斗力是f,对于第i条路,若f > c[i]他花t[i]天就能出去,否则,他就停留一天,同时战斗力增加c[i]然后再选一条路走出去,他走每条路的概率是相同的.问他逃出去的天数的期望. 设dp[i]表示在战斗力为i时逃出去的期望值,那么可推出状态方程 dp[i] = 1/n * t[

zoj 3640 Help Me Escape

Help Me Escapehttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4808 Time Limit: 2 Seconds      Memory Limit: 32768 KB Background     If thou doest well, shalt thou not be accepted? and if thou doest not well, sin lieth at the door. And unto

Help Me Escape (ZOJ 3640)

J - Help Me Escape Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3640 Description Background     If thou doest well, shalt thou not be accepted? and if tho

zoj 3640 概率dp

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4808 Background     If thou doest well, shalt thou not be accepted? and if thou doest not well, sin lieth at the door. And unto thee shall be his desire, and thou shalt rule over him. And Cai

hdu 4035 Maze(比较经典的树形期望DP)

Maze Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 1677    Accepted Submission(s): 638 Special Judge Problem Description When wake up, lxhgww find himself in a huge maze. The maze consisted b