[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. 跨域iframe高度计算

    一.同域获取iframe内容 这里有两个细节: 1. 取iframe内的文档对象,标准浏览器使用contentDocument属性,IE低版本(IE6,7,8)使用document属性. 2. cal ...

  2. python进行EDA探索性数据分析

    1.查看数据的类型概况 cols = [c for c in train.columns]   #返回数据的列名到列表里 print('Number of features: {}'.format(l ...

  3. 【遍历集合】Java遍历List,Map,Vector,Set的几种方法

    关于list,map,set的区别参考http://www.cnblogs.com/qlqwjy/p/7406573.html 1.遍历list @Test public void testList( ...

  4. netlink socket编程

    转载 原文地址:netlink socket编程之why & how (转) 作者:renyuan000 作者: Kevin Kaichuan He@2005-1-5 翻译整理:duanjig ...

  5. 安全测试===burpsuit指南

    网址: https://www.gitbook.com/book/t0data/burpsuite/details 引子 刚接触web安全的时候,非常想找到一款集成型的渗透测试工具,找来找去,最终选择 ...

  6. 【Educational Codeforces Round 19】

    这场edu蛮简单的…… 连道数据结构题都没有…… A.随便质因数分解凑一下即可. #include<bits/stdc++.h> #define N 100005 using namesp ...

  7. expose a port on a living Docker container

    if you have a container that with something running on its port 8000, you can run wget http://contai ...

  8. google fcm 推送的流程

    总结:1.给一个人推,能成功,2.给多个人推,有两种,一种是给组推,一种是给主题推,之前用的是组推,但是不成功,这里换成主题推: <?phpnamespace App\Http\Controll ...

  9. 字符串aaaa......bbbb....ccc...dddddd用正则替换为abcd

    public static void main(String[] args) { String s = "aaaa......bbbb....ccc...dddddd"; Stri ...

  10. python类的使用与多文件组织

    多文件的组织 跨目录级导入模块 from ..xxfile import xxmodule #从上级目录中的xxfile中导入xxmodule import xxsub_dir.xxfile #从xx ...