HDU4405-Aeroplane chess(可能性DP需求预期)
Aeroplane chess
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1182 Accepted Submission(s): 802
at grid i and the dice number is x, he will moves to grid i+x. Hzz finishes the game when i+x is equal to or greater than N.
There are also M flight lines on the chess map. The i-th flight line can help Hzz fly from grid Xi to Yi (0<Xi<Yi<=N) without throwing the dice. If there is another flight line from Yi, Hzz can take the flight line continuously. It is granted that there is
no two or more flight lines start from the same grid.
Please help Hzz calculate the expected dice throwing times to finish the game.
Each test case contains several lines.
The first line contains two integers N(1≤N≤100000) and M(0≤M≤1000).
Then M lines follow, each line contains two integers Xi,Yi(1≤Xi<Yi≤N).
The input end with N=0, M=0.
2 0 8 3 2 4 4 5 7 8 0 0
1.1667 2.3441
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <map>
- using namespace std;
- const int maxn = 100000+10;
- double dp[maxn];
- map<int,int> t;
- map<int,int> flight;
- int n,m;
- void dfs(int sta,int x){
- if(t[x]==0){
- flight[sta] = x;
- }else{
- dfs(sta,t[x]);
- }
- }
- void init(){
- for(map<int,int>::iterator it = t.begin(); it != t.end(); it++){
- dfs(it->first,it->second);
- }
- }
- int main(){
- while(cin >> n >> m && n+m){
- t.clear();
- flight.clear();
- while(m--){
- int a,b;
- scanf("%d%d",&a,&b);
- t[a] = b;
- }
- init();
- dp[n] = 0;
- for(int i = n-1; i >= 0; i--){
- dp[i] = 1;
- for(int k = 1; k <= 6; k++){
- if(i+k <= n){
- if(flight[i+k]==0){
- dp[i] += dp[i+k]/6;
- }else{
- dp[i] += dp[flight[i+k]]/6;
- }
- }
- }
- }
- printf("%.4lf\n",dp[0]);
- }
- return 0;
- }
版权声明:本文博客原创文章,博客,未经同意,不得转载。
HDU4405-Aeroplane chess(可能性DP需求预期)的更多相关文章
- UVA 10529 Dumb Bones 可能性dp 需求预期
主题链接:点击打开链接 题意: 要在一条直线上摆多米诺骨牌. 输入n, l, r 要摆n张排,每次摆下去向左倒的概率是l, 向右倒的概率是r 能够採取最优策略.即能够中间放一段.然后左右两边放一段等, ...
- [hdu4405]Aeroplane chess(概率dp)
题意:某人掷骰子,数轴上前进相应的步数,会有瞬移的情况,求从0到N所需要的期望投掷次数. 解题关键:期望dp的套路解法,一个状态可以转化为6个状态,则该状态的期望,可以由6个状态转化而来.再加上两个状 ...
- HDU4405 Aeroplane chess(期望dp)
题意 抄袭自https://www.cnblogs.com/Paul-Guderian/p/7624039.html 正在玩飞行棋.输入n,m表示飞行棋有n个格子,有m个飞行点,然后输入m对u,v表示 ...
- HDU4405 Aeroplane chess (概率DP,转移)
http://acm.hdu.edu.cn/showproblem.php?pid=4405 题意:在一个1×n的格子上掷色子,从0点出发,掷了多少前进几步,同时有些格点直接相连,即若a,b相连,当落 ...
- 【HDU4405】Aeroplane chess [期望DP]
Aeroplane chess Time Limit: 1 Sec Memory Limit: 32 MB[Submit][Stataus][Discuss] Description Hzz lov ...
- hdu4405 Aeroplane chess
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- [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://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...
- HDU-4405 Aeroplane chess
http://acm.hdu.edu.cn/showproblem.php?pid=4405 看了一下这个博客http://kicd.blog.163.com/blog/static/12696191 ...
随机推荐
- java编程规范之java命名规范
想要成为一个优秀的程序员,首先要培养良好的编程习惯,为了提高代码的可读性,必须有好的命名规范. 这篇文章是小编结合网上的很多资料整理出来的,若有不当或错误的地方,欢迎大家指正 在文章开始前,为方便阅读 ...
- skyeye安装+arm-elf-gdb安装+模拟s3c44b0x+执行ucos4skyeye
[假设你要引用.请阅读所有,这里是我的为期两天的过程只是一个记录] skyeye安装:ubuntu12.0432 llvm2.8 skyeye1.3.3 http://blog.chinaunix.n ...
- Apple Swift编程语言入门
1 简单介绍 今天凌晨Apple刚刚公布了Swift编程语言,本文从其公布的书籍<The Swift Programming Language>中摘录和提取而成.希望对各位的iOS&a ...
- 探秘Java虚拟机——内存管理与垃圾回收(转)
本文主要是基于Sun JDK 1.6 Garbage Collector(作者:毕玄)的整理与总结,原文请读者在网上搜索. 1.Java虚拟机运行时的数据区 2.常用的内存区域调节参数 -Xms:初始 ...
- Chapter06-Phylogenetic Trees Inherited(POJ 2414)(减少国家DP)
Phylogenetic Trees Inherited Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 480 Accepted ...
- PreparedStatement批量处理的一个Framework(原创)
场景:批量进行DML操作,但涉及的表不同,不能使用executeBatch() 需求:(1)如果DML中有一个错误时,要全部回滚:(2)如果全部正确,要全部执行: 解决方案: package jdbc ...
- window批处理-4.call
作用: 批处理中调用还有一个批处理或调用行号后的全部命令 格式: call [FileName] [:label] demo: call.bat: @echo off echo 開始调用called ...
- [Python]sqlite3二进制文件存储问题(BLOB)(You must not use 8-bit bytestrings unless you use a text_factory...)
事情是这种: 博主尝试用Python的sqlite3数据库存放加密后的usernamepassword信息,表是这种 CREATE TABLE IF NOT EXISTS user ( userID ...
- Freemarker详细解释
A概念 最经常使用的概念 1. scalars:存储单值 字符串:简单文本由单或双引號括起来. 数字:直接使用数值. 日期:通常从数据模型获得 布尔值:true或false,通常在<#if -& ...
- Python脚本传參和Python中调用mysqldump
Python脚本传參和Python中调用mysqldump<pre name="code" class="python">#coding=utf-8 ...