HDU 4405 Aeroplane chess(概率dp,数学期望)
http://kicd.blog.163.com/blog/static/126961911200910168335852/
根据里面的例子,就可以很简单的写出来了,虽然我现在还是不是很理解为什么“是下一分钟,故要加上1.”?
好吧,先写着,有事没事想一想,也许时间长了就明白了。
别的人解释很棒:(虽然我还没全懂)
//e[i]表示i的位置走到n所需要的期望步数
//那么e[i]怎么求,首先e[i]走到e[i+1]的概率为1/6 ,
//而e[i+1]是走到终点的期望步数,所以e[i]=e[i+1]*1/6+1,
//为什么加一呢,因为你向前走了一步,期望表示的是步数
//以此类推 e[i]=1+e[i+1]*1/6+e[i+2]*1/6+e[i+3]*1/6...+e[i+6]*1/6
//CF 417 //e[i]表示i的位置走到n所需要的期望步数
//那么e[i]怎么求,首先e[i]走到e[i+1]的概率为1/6 ,
//而e[i+1]是走到终点的期望步数,所以e[i]=e[i+1]*1/6+1,
//为什么加一呢,因为你向前走了一步,期望表示的是步数
//以此类推 e[i]=1+e[i+1]*1/6+e[i+2]*1/6+e[i+3]*1/6...+e[i+6]*1/6 #include <stdio.h>
#include <string.h>
#include<algorithm>
#include<string>
using namespace std;
int mp[];
double e[];
int main()
{ int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==&&m==)break;
memset(mp,,sizeof(mp));
for(int i=;i<m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
mp[x]=y;
}
memset(e,,sizeof(e));
for(int i=n-;i>=;i--)//因为e[n]=0,所以不用再处理它了
{
if(mp[i])e[i]=e[mp[i]];
else
{
for(int j=;j<=;j++)
e[i]+=(1.0/6.0*e[i+j]);
e[i]+=1.0;
}
}
printf("%.4lf\n",e[]);
}
return ;
}
HDU 4405 Aeroplane chess(概率dp,数学期望)的更多相关文章
- [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 难度:0
http://acm.hdu.edu.cn/showproblem.php?pid=4405 明显,有飞机的时候不需要考虑骰子,一定是乘飞机更优 设E[i]为分数为i时还需要走的步数期望,j为某个可能 ...
- 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)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 ...
- 【刷题】HDU 4405 Aeroplane chess
Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled fr ...
- HDU4405-Aeroplane chess(概率DP求期望)
Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz start ...
随机推荐
- Intellij Idea:创建带签名的APK
步骤如下: 1. 选择菜单Build -> Generate Signed APK… 2. 创建或选择已存在的Key Store(选择已存在的Key Store的话直接跳到第5步) 3. 输入K ...
- request.getInputStream() 的两种解析方式
http://sagewsg.iteye.com/blog/1717923 byte[] bytes = new byte[1024 * 1024]; InputStream is; try { is ...
- [Cypress] Test Variations of a Feature in Cypress with a data-driven Test
Many applications have features that can be used with slight variations. Instead of maintaining mult ...
- crmjs区分窗口是否是高速编辑(2)
随着crm的版本号不同,有些功能不能使用,这里提供了第二种写法: function loadFrom() { var formType = Xrm.Page.ui.getFormType(); ...
- WCF学习笔记——契约不能少了set
我定义的WCF契约里,有一个类,里面的属性,有一个因为只读,所以只写了个get.结果客户端就报错. [DataContract] public class UserItem { public User ...
- 【POJ 3074】 Sudoku
[题目链接] http://poj.org/problem?id=3074 [算法] 将数独问题转化为精确覆盖问题,用Dancing Links求解 转化方法如下 : 我们知道,在一个数独中 : 1. ...
- 洛谷P3834 可持久化线段树(主席树)模板
题目:https://www.luogu.org/problemnew/show/P3834 无法忍受了,我要写主席树! 解决区间第 k 大查询问题,可以用主席树,像前缀和一样建立 n 棵前缀区间的权 ...
- bzoj4004 [JLOI2015]装备购买——线性基+贪心
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4004 今天讲课讲到的题,据说满足拟阵的性质,所以贪心是正确的: 总之就贪心,按价格从小到大排 ...
- c++ valarray 实现矩阵与向量相乘
#include <iostream>#include <valarray> template<class T> class Slice_iter { std::v ...
- 83.个人信息维护页面 Extjs 页面
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" ...