跳到正文

个人记录

【ZOJ3640】Help Me Escape

peterwuyihong约 2 分钟
原文
文章信息与版本

文章信息

发布
2020年8月7日
收录
2025年12月12日
更新
2026年10月21日
篇幅
约 2 分钟

版本

  1. v1当前

Help Me EscapeHelp\ Me\ Escape

ZOJ - 3640

题意

一个光头掉到了一个洞里,洞里有nn条路,第ii条路的难度是cic_i,光头一开始有一个能力值ff,若ff此时大于等于cic_i,光头可以花⌊1+52ci2⌋\lfloor \frac{1+\sqrt5}2{c_i^2}\rfloor天走过这条路;不然光头会磨炼11天,并且增加cic_i能力值。

求光头钻出来的期望值(老葛平了

Analysis

我们用记搜做

P[x]P[x]表示能力为xx钻出来的期望天数,如果x≤cix\leq c_i,P[x]P[x]加上dp(x+c[i])+1ndp(x+c[i])+\frac{1}{n};如果x>cix>c_i,P[x]P[x]加上⌊1+52ci2⌋\lfloor \frac{1+\sqrt5}2{c_i^2}\rfloor

C++
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
template<class T>
void read(T &x)
{
	T ans=0;short f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}while(ch>='0'&&ch<='9')
	{
		ans=(ans<<1)+(ans<<3)+(ch^48);
		ch=getchar();
	}x=ans*f;
}

#define maxn 200010
int n,f;
int c[10001];
double P[maxn];
const double p=1.61803398874989;
double dp(int x){
	if(P[x]>-0.5)return P[x];
	P[x]=0;
	for(int i=1;i<=n;i++)
	if(x<=c[i])P[x]+=double(dp(x+c[i])+1.0)/n;
	else P[x]+=int(p*c[i]*c[i])/(double)n;
	return P[x];
}
signed main(){
#ifndef ONLINE_JUDGE
	freopen("testdata.in","r",stdin);
#endif
	while(scanf("%d %d",&n,&f)!=EOF){
		for(int i=0;i<=200000;i++)P[i]=-1;
		for(int i=1;i<=n;i++)read(c[i]);
		printf("%.3lf\n",dp(f));
	}
}
原文