HDU-4405 Aeroplane chess(概率DP求期望)
题目大意:一个跳棋游戏,每置一次骰子前进相应的步数。但是有的点可以不用置骰子直接前进,求置骰子次数的平均值。
题目分析:状态很容易定义:dp(i)表示在第 i 个点出发需要置骰子的次数平均值。则状态转移方程为:
dp(i)=singma(pk*dp(i+k))+1 (如果在 i 处必须置骰子才能前进)
dp(i)=dp(s) (如果在 i 处能直接到达s处)
代码如下:
# include<iostream>
# include<cstdio>
# include<vector>
# include<cstring>
# include<algorithm>
using namespace std; int n,m;
bool flag[100010];
double dp[100010];
vector<int>g[100010]; void init()
{
memset(dp,0,sizeof(dp));
memset(flag,false,sizeof(flag));
for(int i=0;i<=n;++i)
g[i].clear();
int x,y;
while(m--)
{
scanf("%d%d",&x,&y);
g[y].push_back(x);
}
} double solve()
{
for(int i=0;i<g[n].size();++i){
int v=g[n][i];
flag[v]=true;
}
for(int i=n-1;i>=0;--i){
if(!flag[i]){
dp[i]=1.0;
for(int j=1;j<=6;++j)
dp[i]+=dp[i+j]/6.0;
flag[i]=true;
}
for(int j=0;j<g[i].size();++j){
int v=g[i][j];
dp[v]=dp[i];
flag[v]=true;
}
}
return dp[0];
} int main()
{
while(scanf("%d%d",&n,&m)&&(n+m))
{
init();
printf("%.4lf\n",solve());
}
return 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) ...
随机推荐
- 解决python version 2.7 required,which was not find in the registry
程序自动写注册表 http://www.vvivv.com/post-143.html 手工写 http://blog.csdn.net/baikaishui525/article/details/9 ...
- 一个有趣的IE内核检测网站
http://se.360.cn/v5/iecoretest.html 该网站能有效检测您浏览器的内核,以及版本,操作系统. 找到这个网址,是因为最近解决WebBrowser自动调节IE版本功能时发现 ...
- Linksys WRT120N路由器备份文件解析
Perusing the release notes for the latest Linksys WRT120N firmware, one of the more interesting comm ...
- 无线安全渗透测试套件WiFi-Pumpkin新版本发布
WiFi-Pumpkin是一款无线安全检测工具,利用该工具可以伪造接入点完成中间人攻击,同时也支持一些其它的无线渗透功能.旨在提供更安全的无线网络服务,该工具可用来监听目标的流量数据,通过无线钓鱼的方 ...
- ES6:模块简单解释
modules是ES6引入的最重要的一个特性. 以后写模块的时候就直接按照ES6的modules语法来写 ,然后用babel+browserify 来打包就行了. modules规范分两部分,一部分是 ...
- BZOJ 3398 牡牛和牝牛
dp. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> ...
- Camel routes in Spring config file
The normal spring bean definition configuration file, the xsi:schemaLocation only has two: beans and ...
- 利用windows系统ftp命令编写的BAT文件上传[转]
利用windows系统ftp命令编写的BAT文件上传[转] 利用windows系统ftp命令编写的BAT文件上传[转] 在开发中往往需要将本地的程序上传到服务器,而且用惯了linux命令的人来说.在w ...
- JavaScript string.format
//string.format String.prototype.format=function(){ var e = this, f = arguments.length; if (f > 0 ...
- Smart210学习记录------块设备
转自:http://bbs.chinaunix.net/thread-2017377-1-1.html 本章的目的用尽可能最简单的方法写出一个能用的块设备驱动.所谓的能用,是指我们可以对这个驱动生成的 ...