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 ...
随机推荐
- hdu 2481 Toy
好题!!!没话说…… 用到的知识面很多,这题的难点在于公式的推导. 原始推导过程见:http://hi.baidu.com/spellbreaker/item/d8bb3bda5af30be6795d ...
- 分布式内存对象缓存系统Memcached-概述
全面掌握Memcached 1. 概述 Memcached是danga.com(运营LiveJournal的技术团队)开发的一套分布式内存对象缓存系统,是为了加快网站http://www. ...
- asp.net 权限问题
asp.net项目中通过Web.config配置文件及文件夹的访问权限! http://blog.csdn.net/qingyun1029/article/details/6184723
- 卓京---java基础2
2.数据类型 基本类型: 整型: byte字节型 8位(bit) -2^7~2^7-1(-128~127) 0000 0000 short短整型 16位 -2^15~2^15-1(-32768 ...
- C++中全局变量的那些事儿
C/C++中的变量分为全局变量.静态全局变量.局部变量和静态局部变量,在<C/C++中静态局部变量的特点与应用>中我们介绍过静态局部变量,今天我们的目标是全局变量. 单个文件中的全局变量 ...
- 41. First Missing Positive
题目: Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2 ...
- 源代码Log
MVC5源代码 https://github.com/aspnet/Mvc MVC4源代码 http://aspnetwebstack.codeplex.com/
- twitter bootstrap 2.x 3.x区别
栅格系统 (Grid system)说个我认为比较重要的,相对于RC 1中的3层,现在有4层了 We now have .col-xs (phones), .col-sm (tablets), .co ...
- c# 使用 静态类+xml序列化 保存配置文件
namespace TVCorrectionDataProcess{ [XmlRoot(ElementName = "Config")] public class Co ...
- Android开发之获取状态栏高度、屏幕的宽和高
转自:http://blog.csdn.net/guolin_blog/article/details/16919859 获取状态栏的高度. private static int statusBarH ...