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 ...
随机推荐
- [转载] C++ STL string的Copy-On-Write技术
原文: http://coolshell.cn/articles/12199.html stl的string是经过严格优化的, 深入理解对以后编程过程中应用string非常有益处, 感谢左耳朵耗子的精 ...
- 关于css3的自定义字体
css3的@font-face属性打破了中文页面字体一成不变的格局,但今天本菜在用的时候并不那么爽.开始各种引用外部ttf文件失败.下了300M+的字体文件,苦逼的试了一下午.终于有一个ttf引用成功 ...
- sql CHARINDEX函数
CHARINDEX函数返回字符或者字符串在另一个字符串中的起始位置.CHARINDEX函数调用方法如下: CHARINDEX ( expression1 , expression2 [ , start ...
- selenium 加载RemoteDriver浏览器驱动
title NodeWebDriver java -jar selenium-server-standalone-2.42.2.jar -Dwebdriver.ie.driver="C:\S ...
- Selenium解决页面元素不在视野范围内的问题
当需要使用滚动条才能使页面元素显示在视野范围内时,必须用代码处理下,才能对其进行操作. 处理其实也很简单,就是调用JS函数. driver.executeScript("arguments[ ...
- 【bzoj1046】上升序列
[bzoj1046]上升序列 题意 对于一个给定的S={a1,a2,a3,-,an},若有P={ax1,ax2,ax3,-,axm},满足(x1 < x2 < - < xm)且( a ...
- alert与console.log
1.alert在页面中弹出 console.log是在控制台显示 例子 var aa="Silence"; alert(typeof(aa)); console.log(typeo ...
- [Java] Java 获取数据库所有表基本信息和表中的所有列基本信息代码
废话不多说.上代码 import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; import ...
- var isObj = length === undefined || i
这个其实是因为你前面那个===是肯定为false导致的,所以执行到了i那一步了var length=undefined;var a=length===undefined || i;这样你不定义i也是不 ...
- QMessageBox中按钮的汉化
方法一:直接添加汉语按钮: QMessageBox mess(QMessageBox::Question, "删除提示", "确认删除所选组件?", NULL) ...