HDU 4405 Aeroplane chess 概率DP 难度:0
http://acm.hdu.edu.cn/showproblem.php?pid=4405
明显,有飞机的时候不需要考虑骰子,一定是乘飞机更优
设E[i]为分数为i时还需要走的步数期望,j为某个可能投出的点数如果从i向i-j推导,我们并不能确定i的转移方向,因为可能有两个i-j有飞机其目的地是i,所以我们选择从i向i+j推导期望
如果设G[i]为分数为i时已经走过的步数期望,那么要确定G[i+j]需要知道P(i|i+j),也即转移到i+j的条件下从i转移来的概率,比较麻烦
由题意,设match[i]为i处飞机的目的地,则当match[i]存在时,E[i]=E[match[i]],否则E[i]=sigma((E[i+j]+1)*(1/6)),j in range(6)
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1e5+5;
double e[maxn];
int match[maxn];
int n,m;
void init()
{
memset(e,0,sizeof(e));
memset(match,0,sizeof(match));
for(int i=0;i<m;i++){
int f,t;
scanf("%d%d",&f,&t);
match[f]=t;
}
}
int lt(int a){return min(a,n);}
void calc()
{
for(int i=n-1; i>=0; i--)
{
if(match[i]!=0)e[i]=e[lt(match[i])];
else
{
for(int j=1; j<=6; j++)
{
e[i]+=(e[lt(i+j)]+1)/6;
}
}
}
}
int main()
{
for(int ti=1; scanf("%d%d",&n,&m)==2&&(n||m); ti++)
{
init();
calc();
printf("%.4f\n",e[0]);
} return 0;
}
HDU 4405 Aeroplane chess 概率DP 难度:0的更多相关文章
- [ACM] hdu 4405 Aeroplane chess (概率DP)
Aeroplane chess Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 ...
- HDU 4405 Aeroplane chess (概率DP)
题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i 这个位置到达 n ...
- HDU 4405 Aeroplane chess(概率dp,数学期望)
题目 http://kicd.blog.163.com/blog/static/126961911200910168335852/ 根据里面的例子,就可以很简单的写出来了,虽然我现在还是不是很理解为什 ...
- HDU 4405 Aeroplane chess 期望dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...
- hdu 4405 Aeroplane chess (概率DP)
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 4405 Aeroplane chess(概率+dp)
Problem Description Hzz loves aeroplane chess very much. The chess map contains N+ grids labeled to ...
- hdu 4405 Aeroplane chess(简单概率dp 求期望)
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- ZOJ 3822 Domination 概率dp 难度:0
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- 【刷题】HDU 4405 Aeroplane chess
Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled fr ...
随机推荐
- iOS进阶收藏
XCode自带重构方式http://www.cocoachina.com/ios/20160127/15097.html iOS迭代多语言开发http://www.cocoachina.com/ios ...
- [转载] 高效 MacBook 工作环境配置
原文: http://mp.weixin.qq.com/s?__biz=MjM5NzMyMjAwMA==&mid=208231200&idx=1&sn=8a76ddc56c1f ...
- SQL SERVER 2008函数大全(含例子)
--SQL SERVER 2008 函数大全 /* author:TracyLee csdncount:Travylee */ /* 一.字符串函数: 1.ascii(字符串表达式) 返回字符串 ...
- (八)shell中的循环结构
1.for循环(1)要求:能看懂.能改即可.不要求能够完全不参考写出来.因为毕竟嵌入式并不需要完全重新手写shell,系统管理员(服务器运维人员,应用层系统级管理开发的才需要完全掌握shell) 这里 ...
- What is the difference between extensibility and scalability?
You open a small fast food center, with a serving capacity of 5-10 people at a time. But you have en ...
- Hadoop的HA集群启动和停止流程
假设我们有3台虚拟机,主机名分别是hadoop01.hadoop02和hadoop03. 这3台虚拟机的Hadoop的HA集群部署计划如下: 3台虚拟机的Hadoop的HA集群部署计划 hadoop0 ...
- 删除内容并不能删除field structure -- features_revert
把内容删了但field structure还在, 在manage_field界面,field还在.http://drupal.stackexchange.com/questions/21501/rev ...
- phalcon: 查找记录(Finding Records)可用的查询设置如下:
可用的查询设置如下: 参数 描述 举例 conditions Search conditions for the find operation. Is used to extract only tho ...
- 工作常用的linux/mysql/php/工具命令
工作常用的linux/mysql/php/工具命令: 1. tar备份目录 tar zcvf ****.tar.gz ****/ tar 备份跳过目录 tar --exclude=test1 3. s ...
- LocalStorage在Chrome里的实现
前段时间我们在实现CanTK-Runtime时,也曾在V8基础上模拟过浏览器的LocaleStorage功能,其实现非常简单:每个domain的数据使用的单独文件存储,因为同一时间只有一个游戏运行,所 ...