[Codeforces-div.1 24D] Broken robots

试题分析

显然设\(f_{i,j}\)为到\((i,j)\)的期望步数,将转移表达式列出来。

首先自己跟自己的项消掉。

然后规定一个顺序,设\(f_{i+1}\)已知。

那么\(f_i\)转移方程中下一行的项就可以直接计算。

然后进行如下手动消元:

  • 列出转移方程
  • 将上一项带入
  • 自己与自己消元

经过这个过程,每一个位置都可以化为\(f_{i,j} = f_{i,j+1}\times A+B\)的形式。

直接照着方程写就可以了。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm> using namespace std;
#define LL long long inline int read(){
int x=0,f=1; char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
const int INF = 2147483600;
const int MAXN = 100010; int N,M; double f[1001][1001];
int X,Y; double A[1001],B[1001]; int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
N=read(),M=read(); X=read(),Y=read(); N=N-X+1;
if(M==1){printf("%.10lf\n",(N-1)*2.0); return 0;}
for(int i=N-1;i>=1;i--){
A[1]=(3.0+f[i+1][1])/2.0; B[1]=0.5;
for(int j=2;j<M;j++){
A[j]=(4.0+A[j-1]+f[i+1][j])/(3.0-B[j-1]);
B[j]=1.0/(3.0-B[j-1]);
} f[i][M]=(f[i+1][M]+A[M-1]+3.0)/(2.0-B[M-1]);
for(int j=M-1;j>=1;j--){
f[i][j]=f[i][j+1]*B[j]+A[j];
}
} printf("%.10lf\n",f[1][Y]);
return 0;
}

[Codeforces-div.1 24D] Broken robots的更多相关文章

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

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

  2. 【题解】CF24D Broken Robots(收敛性)

    [题解]CF24D Broken Robots http://codeforces.com/problemset/problem/24/D 解1(不会写,口胡的) 获得一个比较显然的转移式子 \(dp ...

  3. Codeforces Round #335 (Div. 2) B. Testing Robots 水题

    B. Testing Robots Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606 ...

  4. Codeforces Round #335 (Div. 2)B. Testing Robots解题报告

                                                                                               B. Testin ...

  5. CodeForces 24D Broken robot (概率DP)

    D. Broken robot time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  6. Codeforces Round #335 (Div. 2) 606B Testing Robots(模拟)

    B. Testing Robots time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. Educational Codeforces Round 75 (Rated for Div. 2) A. Broken Keyboard

    链接: https://codeforces.com/contest/1251/problem/A 题意: Recently Polycarp noticed that some of the but ...

  8. CodeForces 24D Broken Robot

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

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

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

随机推荐

  1. mybatis 插入语句name no find

    1.可参考连接:https://www.cnblogs.com/thomas12112406/p/6217211.html 2.dao层的配置 void addUser(@Param("un ...

  2. 爬虫--requests讲解

    什么是requests? Requests是用Python语言编写,基于urllib,采用Apache2 Licensed 开源协议的HTTP库.它比urllib更加方便,可以节约我们大量的工作,完全 ...

  3. 【转】MP3文件原理及结构解析

    1.引言文件压缩技术的日新月异使得MP3成为时下最烫手的音乐格式,优质的音乐随着0与1的排列迅速散布 到世界各地,撼动人心.何谓MP3?MP3的全称是MPEG Audio Layer 3,它是一种高效 ...

  4. elk + suricata 实验环境详细安装教程

    1.安装运行suricata,需要*** sudo add-apt-repository ppa:oisf/suricata-stable sudo apt-get update sudo apt-g ...

  5. 调试应用程序(Debugging Applications)

    调试应用程序(Debugging Applications)¶ Phalcon中提供了提供了几种调试级别即通知,错误和异常. 异常类 Exception class 提供了错误发生时的一些常用的调试信 ...

  6. sql 自定义split

    以下数据库操作针对sql server. 问题来源:由于项目中,有的表字段内容是由多个id或多个其他内容拼接而成.(如:'1,2,3,4,5',或者'name_age_school'),特点是都用某个 ...

  7. openssl-0.9.8y

    openssl-0.9.8y 支持 32位和64位 编译不报错和向上兼容和向下兼容. http://www.openssl.org/source/openssl-0.9.8y.tar.gz https ...

  8. glom模块的使用(一)

    glom模块的使用 简单说下glom模块主要是处理结构化数据用的,安装简单pip install glom即可,下面就glom的方法参数做例子讲解. glom 和模块同名的glom方法使用方法: .g ...

  9. C#文件路径乱码

    最近学C#,用C#写serialport遇到了一点小问题记录一下. 问题一: if (!string.IsNullOrEmpty(filePath.ToString())) { try { fs = ...

  10. leetcode 之Linked List Cycle(24)

    两个思路,一是用哈希表记录每个结点是还被访问过:二是定义两个快.慢指针,如果存在环的话,两个指针必定会在某位结点相遇. bool linkListNode(ListNode *head) { List ...