ZOJ 3640 Help Me Escape:期望dp
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3640
题意:
有一个吸血鬼被困住了,他要逃跑。。。
他面前有n条路,每条路有一个困难程度c[i]。
他的初始攻击力为f。
每天他会从中随机选一条路:
(1)如果当前攻击力 > c[i],那么他会再花t天走这条路成功逃跑(t的公式如图)。

(2)攻击力 <= c[i],这条路他走不过去,但可以让他的攻击力 += c[i]。
问你成功逃跑所需天数的期望。
题解:
表示状态:
dp[i] = expected time(攻击力为i时,逃跑还需要的天数)
找出答案:
ans = dp[f]
初始攻击力为f。
如何转移:
对于每一条路,每一次被选择的概率都为1/n。
当前攻击力为i,枚举每一条路j,则:
(1)if i > c[j]: dp[i] += t/n (可以用t天逃跑)
(2)else: dp[i] += (dp[i+c[j]]+1)/n (攻击力增加c[j]后所用天数 + 今天一天)
边界条件:
对于一个攻击力max_atk满足max_atk > 所有的c[i],则所有的dp[max_atk]都相等。
(因为只能逃跑,不能再攒攻击力了)
所以找出满足条件的最小的max_atk,max_atk = max( max(c[i]), f )。
可能用到的攻击力最大为max_atk*2。
(根据Code: "else dp[i]+=(dp[i+c[j]]+1)/n")
所以按从max_atk*2到f的顺序求dp就行了。
初始值(设成啥都行。。。没用):set dp = 0
AC Code:
// state expression:
// dp[i] = expected time
// i: present atk
//
// find the answer:
// ans = dp[f]
//
// transferring:
// now: dp[i]
// enum: c[j]
// if i > c[j] dp[i] += t/n
// else dp[i] += (dp[i+c[j]]+1)/n
//
// boundary:
// set dp = 0
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#define MAX_N 105
#define MAX_F 30005 using namespace std; int n,f;
int max_atk;
int c[MAX_N];
double dp[MAX_F]; void read()
{
max_atk=f;
for(int i=;i<n;i++)
{
cin>>c[i];
max_atk=max(max_atk,c[i]);
}
} void solve()
{
memset(dp,,sizeof(dp));
for(int i=max_atk*+;i>=f;i--)
{
for(int j=;j<n;j++)
{
if(i>c[j]) dp[i]+=floor((1.0+sqrt())/2.0*c[j]*c[j])/n;
else dp[i]+=(dp[i+c[j]]+)/n;
}
}
} void print()
{
printf("%.3f\n",dp[f]);
} int main()
{
while(cin>>n>>f)
{
read();
solve();
print();
}
}
ZOJ 3640 Help Me Escape:期望dp的更多相关文章
- zoj 3640 Help Me Escape (概率dp 递归求期望)
题目链接 Help Me Escape Time Limit: 2 Seconds Memory Limit: 32768 KB Background If thou doest w ...
- zoj 3640 Help Me Escape 概率DP
记忆化搜索+概率DP 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...
- ZOJ 3329 Problem Set (期望dp)
One Person Game There is a very simple and interesting one-person game. You have 3 dice, namely Die1 ...
- Help Me Escape (ZOJ 3640)
J - Help Me Escape Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:32768KB ...
- 概率dp ZOJ 3640
Help Me Escape Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit ...
- ZOJ 3822 Domination 期望dp
Domination Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem ...
- poj 2096 , zoj 3329 , hdu 4035 —— 期望DP
题目:http://poj.org/problem?id=2096 题目好长...意思就是每次出现 x 和 y,问期望几次 x 集齐 n 种,y 集齐 s 种: 所以设 f[i][j] 表示已经有几种 ...
- 【HDU3853】LOOPS [期望DP]
LOOPS Time Limit: 5 Sec Memory Limit: 64 MB[Submit][Status][Discuss] Description Akemi Homura is a ...
- 【BZOJ-1419】Red is good 概率期望DP
1419: Red is good Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 660 Solved: 257[Submit][Status][Di ...
随机推荐
- 96Boards扩展板 STM32 B96B-F446VE 牛刀小试
前言 原创文章,转载引用务必注明链接,水平有限,如有疏漏,欢迎指正. 本文使用Markdown写成,为获得更好的阅读体验和正常的链接.图片显示,请访问我的博客原文: http://www.cnblog ...
- KVO(1)
#import "ViewController.h" @interface ViewController () @property(nonatomic, strong)UIButt ...
- vue2.0 仿手机新闻站(七)过滤器、动画效果
1.全局过滤器 (1)normalTime.js 自定义 将 时间戳 转换成 日期格式 过滤器 /** * 将 时间戳 转换成 日期格式 */ export const normalTime = ( ...
- Nexus 5刷阿里云OS
刷机有风险,刷机需慎重! 1. 下载 recovery 的img和 阿里云os. recovery 的img下载: https://kanbox.com/f/V00KA 阿里云OS3.0.3 : 2月 ...
- vector(可变数组) 用于UDP通信
头文件: #include<vector.h> 然后,声明并初始化vctor数组. vector<char> str(len); 其中len可以是变量或者常量.(其实用常量就 ...
- RobotFramework-Selenium2Library--关键字
Selenium2Library用户关键字 *** Settings *** Library Selenium2Library *** Keywords *** Checkbox应该不被选择 [Arg ...
- nodejs 简单的备份github代码初版
传送门:http://www.jianshu.com/p/002efed0d3af 我的代码: const https = require('https'); const fs = require(& ...
- C语言日期计算器
记录下码子 # define _CRT_SECURE_NO_WARNINGS # include <stdio.h> # include <stdlib.h> int days ...
- 简单的js表单验证框架
/** * 通常在我们的HTML页面表单中有大量的数据验证工作, * 免不了要写很多验证表单的js代码,这是一项非常繁琐 * 枯燥的工作.很多程序员也会经常遗漏这项工作.当然 * 一些JavaEE框架 ...
- git是一种分布式代码管理工具,git通过树的形式记录文件的更改历史,比如: base'<--base<--A<--A' ^ | --- B<--B' 小米工程师常常需要寻找两个分支最近的分割点,即base.假设git 树是多叉树,请实现一个算法,计算git树上任意两点的最近分割点。 (假设git树节点数为n,用邻接矩阵的形式表示git树:字符串数组matrix包含n个字符串,每个字符串由字符'0
// ConsoleApplication10.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream& ...