CodeForces 24D Broken robot (概率DP)
2 seconds
256 megabytes
standard input
standard output
You received as a gift a very clever robot walking on a rectangular board. Unfortunately, you understood that it is broken and behaves rather strangely (randomly). The board consists of N rows
and Mcolumns of cells. The robot is initially at some cell on the i-th
row and the j-th column. Then at every step the robot could go to some another cell. The aim is to go to the bottommost (N-th)
row. The robot can stay at it's current cell, move to the left, move to the right, or move to the cell below the current. If the robot is in the leftmost column it cannot move to the left, and if it is in the rightmost column it cannot move to the right. At
every step all possible moves are equally probable. Return the expected number of step to reach the bottommost row.
On the first line you will be given two space separated integers N andM (1 ≤ N, M ≤ 1000).
On the second line you will be given another two space separated integers i and j (1 ≤ i ≤ N, 1 ≤ j ≤ M)
— the number of the initial row and the number of the initial column. Note that, (1, 1) is the upper left corner of the board and (N, M) is
the bottom right corner.
Output the expected number of steps on a line of itself with at least 4digits after the decimal point.
10 10
10 4
0.0000000000
10 14
5 14
18.0038068653
概率DP
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector> using namespace std;
int n,m;
int x,y;
double dp[1005][1005];
int main()
{
scanf("%d%d",&n,&m);
scanf("%d%d",&x,&y);
double p1=1.0/3;
double p2=1.0/4;
double p3=1.0/2;
for(int i=n-1;i>=x;i--)
{
for(int t=0;t<=50;t++)
{
for(int j=1;j<=m;j++)
{
if(m==1)
dp[i][j]=(dp[i+1][j]*p3+1)/(1-p3);
else if(j==1)
dp[i][j]=(dp[i][j+1]*p1+dp[i+1][j]*p1+1)/(1-p1);
else if(j==m)
dp[i][j]=(dp[i][j-1]*p1+dp[i+1][j]*p1+1)/(1-p1);
else
dp[i][j]=(dp[i][j+1]*p2+dp[i][j-1]*p2+dp[i+1][j]*p2+1)/(1-p2);
}
}
}
printf("%.6f\n",dp[x][y]);
return 0;
}
CodeForces 24D Broken robot (概率DP)的更多相关文章
- Codeforces.24D.Broken robot(期望DP 高斯消元)
题目链接 可能这儿的会更易懂一些(表示不想再多写了). 令\(f[i][j]\)表示从\((i,j)\)到达最后一行的期望步数.那么有\(f[n][j]=0\). 若\(m=1\),答案是\(2(n- ...
- CodeForces 24D Broken robot(期望+高斯消元)
CodeForces 24D Broken robot 大致题意:你有一个n行m列的矩形板,有一个机器人在开始在第i行第j列,它每一步会随机从可以选择的方案里任选一个(向下走一格,向左走一格,向右走一 ...
- CodeForces 24D Broken Robot
题意:n*m的棋盘,一个机器人在(i,j)处,每次等概率地停在原地,向左移动一格,向右移动一格,向下移动一格(不能移出棋盘).求走到最后一行所需期望步数.n<=1000,m<=1000 一 ...
- codeforces 24d Broken robot 期望+高斯消元
题目传送门 题意:在n*m的网格上,有一个机器人从(x,y)出发,每次等概率的向右.向左.向下走一步或者留在原地,在最左边时不能向右走,最右边时不能像左走.问走到最后一行的期望. 思路:显然倒着算期望 ...
- HDU 4576 Robot(概率dp)
题目 /*********************复制来的大致题意********************** 有N个数字,M个操作, 区间L, R. 然后问经过M个操作后落在[L, R]的概率. * ...
- CodeForces - 24D :Broken robot (DP+三对角矩阵高斯消元 随机)
pro:给定N*M的矩阵,以及初始玩家位置. 规定玩家每次会等概率的向左走,向右走,向下走,原地不动,问走到最后一行的期望.保留4位小数. sol:可以列出方程,高斯消元即可,发现是三角矩阵,O(N* ...
- BZOJ 3270 博物馆 && CodeForces 113D. Museum 期望概率dp 高斯消元
大前提,把两个点的组合看成一种状态 x 两种思路 O(n^7) f[x]表示在某一个点的前提下,这个状态经过那个点的概率,用相邻的点转移状态,高斯一波就好了 O(n^6) 想象成臭气弹,这个和那个的区 ...
- 【CF24D】Broken Robot (DP+高斯消元)
题目链接 题意:给定一个\(n\times m\)的矩阵,每次可以向→↓←移动一格,也可以原地不动,求从\((x,y)\)到最后一行的期望步数. 此题标签\(DP\) 看到上面这个肯定会想到 方法一: ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
随机推荐
- mysql基础知识详解
分享一些mysql数据库的基础知识. 1.每个客户端连接都会从服务器进程中分到一个属于它的线程.而该连接的相应查询都都会通过该线程处理.2.服务器会缓存线程.因此并不会为每个新连接创建或者销毁线程.3 ...
- 如何利用dex2jar反编译APK
工具/原料 电脑 dex2jar JD-GUI 方法/步骤 1 下载dex2jar和JD-GUI,在参考资料中添加了这两个工具的百度网盘下载地址供读者下载使用(笔者亲测) 2 找到我们准备测试用的ap ...
- php7性能、兼容性和稳定性探讨
前几天看到php7发布了beta1版本,想了解一下php7到底折腾了些啥东西出来.这一了解发现不得了了,改变还挺多的.最最重要的方面就是性能提升了不少,这边有一个pdf文件是惠新宸(鸟哥,php核心开 ...
- GPIO—位带操作
GPIO—位带操作本章参考资料:< STM32F4xx 中文参考手册>存储器和总线构架章节. GPIO 章节,< Cortex®-M4 内核编程手册> 2.2.5 Bit-ba ...
- 用广搜实现的spfa
用广搜实现的spfa,如果是用一般的最短路,会发现构图很麻烦,因为它不是路径带权值,而是自身带权值.写起来只要注意,在点出队列的生活将其标记为0,在要压入队列的时候,判断其标记是否为0,为0表示队列中 ...
- linux如何查看CPU,内存,机器型号,网卡信息
查看CPU信息(型号)# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c 8 Intel(R) Xeon(R) CPU ...
- 浅谈weblogic与tomcat的区别
weblogic是用于开发.集成.部署和管理大型分布式web应用.网络应用和数据库应用的java应用服务器,将java的动态功能和java enterprise标准的安全性引入大型网络应用的开发集成部 ...
- 一个性能较好的JVM参数配置(转)
一个性能较好的web服务器jvm参数配置: -server//服务器模式-Xmx2g //JVM最大允许分配的堆内存,按需分配-Xms2g //JVM初始分配的堆内存,一般和Xmx配置成一样以避免每次 ...
- Linux下protobuf的编译与安装
1.下载源码 首先,从github上下载protobuf的源码,地址:https://github.com/google/protobuf,我选择下载2.5.0版本. 2.编译protobuf 将下载 ...
- jquery checkbox勾选/取消
作者:@keenleung本文为作者原创,转载请注明出处:http://www.cnblogs.com/KeenLeung/p/3799895.html 目录 <form> 你爱好的运动是 ...