HDU 4405 Aeroplane chess:期望dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4405
题意:
你在下简化版飞行棋。。。
棋盘为一个线段,长度为n。
上面有m对传送门,可以直接将你从a[i]传送到b[i]处。
每扔一次骰子,可以向前移动的步数为骰子的点数。
你的初始位置为0。当位置>=n时,游戏结束。
问你扔骰子次数的期望。
题解:
表示状态:
dp[i] = rest steps
位置为i时,剩余需要掷骰子次数的期望。
找出答案:
ans = dp[0](初始位置)
如何转移:
每次掷骰子点数分别为1至6的概率均为1/6。
dp[i] = sigma (dp[i+j] * 1/6) + 1
特别地,当i为某个传送门的入口时,只能转移到出口处。所以此时dp[i] = dp[trans[i]].
边界条件:
set dp = 0
i >= n表明游戏已经结束,dp[i]为0.
i < n的dp[i]会在for循环中更新,所以不用管。
AC Code:
// state expression:
// dp[i] = rest steps
// i: present pos
//
// find the answer:
// ans = dp[0]
//
// transferring:
// now: dp[i]
// dp[i] = sigma (dp[i+j] * 1/6) + 1
//
// boundary:
// set dp = 0
#include <iostream>
#include <stdio.h>
#include <string.h>
#define MAX_N 100010 using namespace std; int n,m;
int trans[MAX_N];
double dp[MAX_N]; void read()
{
memset(trans,-,sizeof(trans));
int a,b;
for(int i=;i<m;i++)
{
cin>>a>>b;
trans[a]=b;
}
} void solve()
{
memset(dp,,sizeof(dp));
for(int i=n-;i>=;i--)
{
if(trans[i]!=-)
{
dp[i]=dp[trans[i]];
continue;
}
for(int j=;j<=;j++)
{
dp[i]+=dp[i+j]/6.0;
}
dp[i]+=1.0;
}
} void print()
{
printf("%.4f\n",dp[]);
} int main()
{
while(cin>>n>>m)
{
if(n== && m==) break;
read();
solve();
print();
}
}
HDU 4405 Aeroplane chess:期望dp的更多相关文章
- HDU 4405 Aeroplane chess 期望dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...
- [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,数学期望)
题目 http://kicd.blog.163.com/blog/static/126961911200910168335852/ 根据里面的例子,就可以很简单的写出来了,虽然我现在还是不是很理解为什 ...
- HDU 4405 Aeroplane chess 概率DP 难度:0
http://acm.hdu.edu.cn/showproblem.php?pid=4405 明显,有飞机的时候不需要考虑骰子,一定是乘飞机更优 设E[i]为分数为i时还需要走的步数期望,j为某个可能 ...
- HDU 4405 Aeroplane chess (概率DP)
题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i 这个位置到达 n ...
- hdu 4405 Aeroplane chess(简单概率dp 求期望)
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 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 ...
- 【HDU4405】Aeroplane chess [期望DP]
Aeroplane chess Time Limit: 1 Sec Memory Limit: 32 MB[Submit][Stataus][Discuss] Description Hzz lov ...
- 【刷题】HDU 4405 Aeroplane chess
Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled fr ...
随机推荐
- Sublime3破解教程[转载]
sublime text 3 这个IDE相信很多人认识,尤其是python的.相对pycharm ide而言,速度快.界面清爽等优点,下面就分享下各个版本的破解方法 用UltraEdit等编辑器打开s ...
- java web邮件收发
1.网上方法要导入两个包 mail.jar&activation.jar package com.zjh.shopping.util; import java.util.Date; impor ...
- Android · PendingIntent学习
Intent 是及时启动,intent 随所在的activity 消失而消失 PendingIntent用于处理即将发生的事情.比如在通知Notification中用于跳转页面,但不是马上跳转. ...
- 事件绑定,事件捕获,事件冒泡以及事件委托,兼容IE
● 事件分为三个阶段: 事件捕获 --> 事件目标 --> 事件冒泡 ● 事件捕获:事件发生时(onclick,onmouseover……)首先发生在document上,然后依次传 ...
- SQL存在一个表而不在还有一个表中的数据
select a.id,a.oacode,a.custid,a.custname,a.xsz,a.salename,a.communicationtheme,a.communicationproper ...
- objc_msgSend 报错
NSMutableArray * mutableArray = [NSMutableArray arrayWithArray:array]; objc_msgSend(mutableArray,@se ...
- Excel工作表忘记密码如何破解?
第一种方法就是按住快捷键ALT+F11,然后切换出VBA编辑窗口,如图一:在该窗口的左侧我们的选择那个忘记密码的工作表,比如sheet 1... 2 然后我们复制以下代码 “Sub Pojie()Ac ...
- Ubuntu Server 安装 NodeJS
准备命令: $ sudo apt-get install python $ sudo apt-get install build-essential $ sudo apt-get install gc ...
- idea 的IDE
idea 是与eclipse齐名的IDE(集成开发工具),以智能闻名,不过对于熟悉eclipse的的用户来说,初次接触idea有些让人搞不清方向,下面介绍一下简单的使用 方式. 1.安装 官网下载ul ...
- 将web工程部署到tomcat
http://blog.csdn.net/lucklq/article/details/7621807 http://jingyan.baidu.com/article/466506582f2f4af ...