HDU 4405-Aeroplane chess(概率dp)
题意:
n+1格飞行棋,编号0-n,从0格开始,每次扔一个色子,得到的点数就向前走几步,但有有些格子到达后可以直接飞到后面的格子,
当到达>=n的地方结束,求结束扔色子的期望次数。
分析:
dp[i]表示i格到结束需要的期望次数,dp[n]-dp[n+5]是0,dp[0]即为所求,先处理直接飞的情况
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define N 100010
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
double dp[N];
//fly[i]i格可以最终飞到的格子
int fly[N],n,m;
void solve(){
memset(dp,,sizeof(dp));
for(int i=n-;i>=;--i){
if(fly[i]!=-){
dp[i]=dp[fly[i]];//可由前面的格子飞过来
}
else{
//6种情况
for(int j=;j<=;++j)
dp[i]+=dp[i+j]/6.0;
dp[i]+=1.0;
}
}
printf("%.4lf\n",dp[]);
}
int main()
{
while(~scanf("%d%d",&n,&m)){
if(n==&&m==)break;
memset(fly,-,sizeof(fly));
int u,v;
while(m--){
scanf("%d%d",&u,&v);
fly[u]=v;
}
for(int i=;i<=n;++i){
int j=fly[i];
if(j==-)continue;
while(fly[j]!=-){
j=fly[j];
}
fly[i]=j;
}
solve();
}
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://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 ...
- 【刷题】HDU 4405 Aeroplane chess
Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled fr ...
- HDU 4405 Aeroplane chess (概率DP求期望)
题意:有一个n个点的飞行棋,问从0点掷骰子(1~6)走到n点须要步数的期望 当中有m个跳跃a,b表示走到a点能够直接跳到b点. dp[ i ]表示从i点走到n点的期望,在正常情况下i点能够到走到i+1 ...
随机推荐
- POJ3253Babelfish
http://poj.org/problem?id=3253 就是一个哈夫曼树,题目下边有提示,所以题意还是好理解的 #include<cstdio> #include<cstrin ...
- HBase入门
/×××××××××××××××××××××××××××××××××××××××××/ Author:xxx0624 HomePage:http://www.cnblogs.com/xxx0624/ ...
- java 写文本文件
code 1:将特定String写入特定文件,不覆盖. import java.io.*; import java.util.*; public class OutputLog { public st ...
- React开发项目例子
一.需求 1.分析:用react开发一个类似bootstrap4中的card组件http://v4-alpha.getbootstrap.com/components/card/,界面类似如下: 2. ...
- s.charAt()
public class ish{public static void main(String[]args){ String s="call me ishmae";System.o ...
- NPOI基础入门(旧版本)
1.常用的类与方法 工作本HSSFWorkbook 构造方法,无参表示创建一个新的工作本,可以接收一个流用于打开一个现有的工作本 方法CreateSheet(索引):创建指定索引的sheet对象 方法 ...
- Java API —— System类
1.System类概述 System 类包含一些有用的类字段和方法.它不能被实例化. 2.成员方法 public static void gc():运行垃圾回收器 ...
- Eliza Doolittle lyrics Big City
Eliza Doolittle lyrics Big City 歌词很好,现在还没有,以后添加进来.
- NDK(19)简单示例:ndk调用java基本方法、数组;使用stl、访问设备
一.ndk调用java类示例 1,调用基本方法 /* * Class: com_example_ndksample_MainActivity * Method: ndkFindJavaClass * ...
- 函数ut_bit_set_nth
/*****************************************************************//** Sets the nth bit of a ulint. ...