ZOJ 3640 Help Me Escape [概率DP]

本博客探讨了一个在充满危险的环境中,通过战斗能力与路径难度的关系,计算最终逃脱所需时间期望的问题。利用动态规划的方法,实现了一个高效的解决策略。

Description

Now Cain is unexpectedly trapped in a cave with N paths. Due to LORD's punishment, all the paths are zigzag and dangerous. The difficulty of the ith path is ci.

Then we define f as the fighting capacity of Cain. Every day, Cain will be sent to one of the N paths randomly.

Suppose Cain is in front of the ith path. He can successfully take ti days to escape from the cave as long as his fighting capacity f is larger than ci. Otherwise, he has to keep trying day after day. However, if Cain failed to escape, his fighting capacity would increase cias the result of actual combat. (A kindly reminder: Cain will never died.)

As for ti, we can easily draw a conclusion that ti is closely related to ci. Let's use the following function to describe their relationship:

After D days, Cain finally escapes from the cave. Please output the expectation of D.


题意:

给出N条逃跑路径,每条路径有一个困难值Ci,Cain要逃跑,一开始其有战斗值f,他可以花费一个单位的时间来等概率随机选择其中一条路径逃跑,如果其战斗值f大于Ci,则在经过Ti时间(公式如上)后成功,如果小于等于,则失败(不会多花时间),且战斗值f增长Ci,问逃跑所需要的时间的期望。

范围:

N<=100,f<=1000000,Ci<=10000

解法:

发现最后逃跑时,只要f大于最大的一个Ci(记为M-1),必定可以逃跑,则可以考虑DP,DP[I]表示当前战斗力为I,还需要期望花费DP[I]才能成功逃跑,可知DP[M]=Σ1/N * Ti

确定了边界条件后,转移方程就很简单了:

DP[I]=1/N* ( ΣTj +Σ(dp[K]+1) ) 其中J为当前战斗力I已经可以逃生的路径,K为还不可逃生的路径,注意转移时不要越界。

代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<iostream>
#include<stdlib.h>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<bitset>
#pragma comment(linker, "/STACK:1024000000,1024000000")
template <class T>
bool scanff(T &ret){ //Faster Input
    char c; int sgn; T bit=0.1;
    if(c=getchar(),c==EOF) return 0;
    while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar();
    sgn=(c=='-')?-1:1;
    ret=(c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
    if(c==' '||c=='\n'){ ret*=sgn; return 1; }
    while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10;
    ret*=sgn;
    return 1;
}
#define inf 1073741823
#define llinf 4611686018427387903LL
#define PI acos(-1.0)
#define lth (th<<1)
#define rth (th<<1|1)
#define rep(i,a,b) for(int i=int(a);i<=int(b);i++)
#define drep(i,a,b) for(int i=int(a);i>=int(b);i--)
#define gson(i,root) for(int i=ptx[root];~i;i=ed[i].next)
#define tdata int testnum;scanff(testnum);for(int cas=1;cas<=testnum;cas++)
#define mem(x,val) memset(x,val,sizeof(x))
#define mkp(a,b) make_pair(a,b)
#define findx(x) lower_bound(b+1,b+1+bn,x)-b
#define pb(x) push_back(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

double dp[10010];
int c[10010];
int n,m,f;
double s=(sqrt(5.0)+1.0)/2.0;
int main(){
    while(scanf("%d",&n)!=EOF){
        scanff(f);
        m=-inf;
        rep(i,1,n){
            scanff(c[i]);
            m=max(m,c[i]);
        }
        m++;
        dp[m]=0;
        rep(i,1,n){
            dp[m]+=floor(s*double(c[i]*c[i]));
        }
        dp[m]/=double(n);
        drep(i,m-1,f){
            dp[i]=0;
            rep(j,1,n){
                if(c[j]<i)dp[i]+=floor(s*double(c[j]*c[j]));
                else{
                    int k=min(i+c[j],m);
                    dp[i]+=dp[k]+1;
                }
            }
            dp[i]/=n;
        }
        printf("%.3lf\n",dp[f]);

    }

}



"Mstar Bin Tool"是一款专门针对Mstar系列芯片开发的固件处理软件,主要用于智能电视及相关电子设备的系统维护与深度定制。该工具包特别标注了"LETV USB SCRIPT"模块,表明其对乐视品牌设备具有兼容性,能够通过USB通信协议执行固件读写操作。作为一款专业的固件编辑器,它允许技术人员对Mstar芯片的底层二进制文件进行解析、修改与重构,从而实现系统功能的调整、性能优化或故障修复。 工具包中的核心组件包括固件编译环境、设备通信脚本、操作界面及技术文档等。其中"letv_usb_script"是一套针对乐视设备的自动化操作程序,可指导用户完成固件烧录全过程。而"mstar_bin"模块则专门处理芯片的二进制数据文件,支持固件版本的升级、降级或个性化定制。工具采用7-Zip压缩格式封装,用户需先使用解压软件提取文件内容。 操作前需确认目标设备采用Mstar芯片架构并具备完好的USB接口。建议预先备份设备原始固件作为恢复保障。通过编辑器修改固件参数时,可调整系统配置、增删功能模块或修复已知缺陷。执行刷机操作时需严格遵循脚本指示的步骤顺序,保持设备供电稳定,避免中断导致硬件损坏。该工具适用于具备嵌入式系统知识的开发人员或高级用户,在进行设备定制化开发、系统调试或维护修复时使用。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值