HDU 4405 Aeroplane chess (概率DP求期望)
题意:有一个n个点的飞行棋,问从0点掷骰子(1~6)走到n点须要步数的期望
当中有m个跳跃a,b表示走到a点能够直接跳到b点。
dp[ i ]表示从i点走到n点的期望,在正常情况下i点能够到走到i+1,i+2,i+3,i+4,i+5,i+6 点且每一个点的概率都为1/6
所以dp[i]=(dp[i+1]+dp[i+2]+dp[i+3]+dp[i+4]+dp[i+5]+dp[i+6])/6 + 1(步数加一)。
而对于有跳跃的点直接为dp[a]=dp[b];
#include<stdio.h>
#include<string.h>
#include<string>
#include<map>
#include<stack>
#include<math.h>
#include<queue>
#include<vector>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 100000
map<int,int> mp;
int main()
{
int n,m;
double dp[maxn];
while(scanf("%d%d",&n,&m))
{
if(n==0&&m==0) break;
int a,b;
for(int i=0;i<=n;i++)
mp[i]=-1;
while(m--)
{
scanf("%d%d",&a,&b);
mp[a]=b;
}
memset(dp,0.0,sizeof(dp));
for(int i=n-1;i>=0;i--)
{
if(mp[i]!=-1) dp[i]=dp[mp[i]];
else
{
for(int j=1;j<=6;j++)
dp[i]+=dp[i+j];
dp[i]=dp[i]/6+1;
}
}
printf("%.4lf\n",dp[0]);
}
return 0;
}
/*
2 0
8 3
2 4
4 5
7 8
0 0
*/
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,数学期望)
题目 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为某个可能 ...
- HDU4405-Aeroplane chess(概率DP求期望)
Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz start ...
- HDU3853-LOOPS(概率DP求期望)
LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Total Su ...
- HDU 4405 Aeroplane chess 期望dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...
- POJ2096 Collecting Bugs(概率DP,求期望)
Collecting Bugs Ivan is fond of collecting. Unlike other people who collect post stamps, coins or ot ...
- 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) ...
随机推荐
- hbuilder中的 http://www.w3.org/TR/html4/loose.dtd
<!-- This is the HTML 4.01 Transitional DTD, which includes presentation attributes and elements ...
- J2EE集群原理(摘录)
J2EE集群原理 什么是集群呢?总的来说,集群包括两个概念:“负载均衡”(load balancing)和“失效备援”(failover) 图一:负载均衡 多个客户端同时发出请求,位于前端的负载均衡 ...
- 淘宝ip地址库接口会导致TTFB时间变长,网站打开速度变慢
前一段时间闲来无事发现别人的网站上有显示当前用户城市的功能,就自己也整了一个 这是淘宝ip地址库调用方法 然后问题就出现了,网站打开速度慢的要死 用F12发现是TTFB太慢,然后百度了,发现了问题的原 ...
- Ch03 React/JSX/Component 簡介
Facebook 本身有提供 Test Utilities,但由于不够好用,所以目前主流开发社群比较倾向使用 Airbnb 团队开发的 enzyme,其可以与市面上常见的测试工具(Mocha.Karm ...
- DB2使用收集
db2命令收集 创建带分区的表: create table table_name( )in table_space index in index_space partition by range(c ...
- servlet-响应信息
package servlet; import java.io.IOException; import javax.servlet.ServletException; import javax.ser ...
- vs for Mac中的启用Entity Framework Core .NET命令行工具
在vs for Mac的工具菜单中已没有了Package Manager Console. 我们可以通过以下方法使用Entity Framework Core .NET命令行工具: 1.添加Nuget ...
- =new、=null、.clear()、system.gc()的区别
开发经验告诉我 = new是指向另一个地址空间 =null对象被回收 .clear()对象被清空,但是仍然指向原来的地址空间 这三种方式都并没有真正的清理内存 只有system.gc()是直接清理,但 ...
- Review:Microbiota, metagenome, microbiome傻傻分不清
Microbiota 微生物群 微生物群是指研究动植物体上共生或病理的微生物生态群体.微生物群包括细菌.古菌.原生动物.真菌和病毒.研究表明其在宿主的免疫.代谢和激素等方面非常重要.近义词Micr ...
- PHP 之sha256 sha512封装
/* PHP sha256 sha512目前(PHP 7.1)没有内置的函数来计算,sha1() sha1_file() md5() md5_file()分别可以用来计算字符串和文件的sha1散列值和 ...