D. Broken robot
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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

Output the expected number of steps on a line of itself with at least 4digits after the decimal point.

Examples
input
10 10
10 4
output
0.0000000000
input
10 14
5 14
output
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)的更多相关文章

  1. Codeforces.24D.Broken robot(期望DP 高斯消元)

    题目链接 可能这儿的会更易懂一些(表示不想再多写了). 令\(f[i][j]\)表示从\((i,j)\)到达最后一行的期望步数.那么有\(f[n][j]=0\). 若\(m=1\),答案是\(2(n- ...

  2. CodeForces 24D Broken robot(期望+高斯消元)

    CodeForces 24D Broken robot 大致题意:你有一个n行m列的矩形板,有一个机器人在开始在第i行第j列,它每一步会随机从可以选择的方案里任选一个(向下走一格,向左走一格,向右走一 ...

  3. CodeForces 24D Broken Robot

    题意:n*m的棋盘,一个机器人在(i,j)处,每次等概率地停在原地,向左移动一格,向右移动一格,向下移动一格(不能移出棋盘).求走到最后一行所需期望步数.n<=1000,m<=1000 一 ...

  4. codeforces 24d Broken robot 期望+高斯消元

    题目传送门 题意:在n*m的网格上,有一个机器人从(x,y)出发,每次等概率的向右.向左.向下走一步或者留在原地,在最左边时不能向右走,最右边时不能像左走.问走到最后一行的期望. 思路:显然倒着算期望 ...

  5. HDU 4576 Robot(概率dp)

    题目 /*********************复制来的大致题意********************** 有N个数字,M个操作, 区间L, R. 然后问经过M个操作后落在[L, R]的概率. * ...

  6. CodeForces - 24D :Broken robot (DP+三对角矩阵高斯消元 随机)

    pro:给定N*M的矩阵,以及初始玩家位置. 规定玩家每次会等概率的向左走,向右走,向下走,原地不动,问走到最后一行的期望.保留4位小数. sol:可以列出方程,高斯消元即可,发现是三角矩阵,O(N* ...

  7. BZOJ 3270 博物馆 && CodeForces 113D. Museum 期望概率dp 高斯消元

    大前提,把两个点的组合看成一种状态 x 两种思路 O(n^7) f[x]表示在某一个点的前提下,这个状态经过那个点的概率,用相邻的点转移状态,高斯一波就好了 O(n^6) 想象成臭气弹,这个和那个的区 ...

  8. 【CF24D】Broken Robot (DP+高斯消元)

    题目链接 题意:给定一个\(n\times m\)的矩阵,每次可以向→↓←移动一格,也可以原地不动,求从\((x,y)\)到最后一行的期望步数. 此题标签\(DP\) 看到上面这个肯定会想到 方法一: ...

  9. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

随机推荐

  1. [转]如何为图片添加热点链接?(map + area)

    原文地址:https://www.cnblogs.com/jf-67/p/8135004.html 所谓图片热点链接就是为图片指定一个或多个区域以实现点击跳转到指定的页面.简单来说就是点击某一区域就能 ...

  2. Delphi映射模式实验

    unit FrmMappingMode; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Contro ...

  3. 安装wxWidgets遭遇的两大关卡

    早就想体验wxWidgets.这学期的C++课,课时还算充裕.关键是弟子们的实践能跟得上,我希望能让他们也浅尝一把GUI开发. MFC能够选.但既然IDE都用CodeBlocks了.还是选wxWidg ...

  4. Struts2初学 Struts2的action接收用户数据方式

    一.简介    开发Web应用程序,首先应会遇到对用户输入数据的接收,传统的Web应用程序是由开发人员调用HttpServletRequest的getparameter(String name)方法从 ...

  5. select下拉选框的默认值,包括每次进入页面的默认值

    下拉选: <select onchange="selectTotal(this.value)" style="width: 50px;">      ...

  6. SpringMVC之学习(1)

    先来一个springmvc的基本配置,照样输出hello world 1.先导入springmvc所需要的开发包 最起码需要这么多的基本包,然后开始上配置 2.先在web.xml里进行引入,和Stru ...

  7. RP2836 板卡信息标识

    RP2836 板卡信息标识 可以标识16种扩展应用 MCI_DA4 PD5     R120上拉 R121下拉 MCI_DA5  PD6 R125上拉 R124下拉 MCI_DA6  PD7 R122 ...

  8. at91 uart driver for vxworks

    /* at91UART.c - AT91RM9200 serial driver */ /* Copyright 2003-2004 Coordinate Co., Ltd. */ /* Copyri ...

  9. CI框架中 类名不能以方法名相同

    昨天晚上一个坑爹的问题折腾了我一晚上,首先我来说下我的代码,我建立了一个index的控制器然后呢  在控制器里有一个index的方法.页面模板都有. if ( ! defined('BASEPATH' ...

  10. sql 语句 查询两个字段都相同的方法

    这是替代方法 先使用着 select * from ofgroup where groupId in (select groupId from ofgroup where  uid ='". ...