题目: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2271

题意:一个N*N的矩阵( N = 2*k-1 , k<=50) , 有一个 MM 站在矩阵的中央(k,k),MM 可以朝上下左右四个方向走动,不能走出去,

而 you 首先站在(0,k)的位置上,you每次只能向右走一步,求you遇到MM的概率~

思路: dp[t][x][y]  表示MM在t时刻到达坐标为 (x, y) 的概率,

    那么 dp[t][x][y] = dp[t-1][x'][y']*p(x', y')  , p(x', y') 表示在坐标(x,'  y')时走到坐标(x, y)的概率~

    初始化 dp[0][k][k]=1;

 

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int dir[ ][ ] = {,,,,-,,,-};
double dp[][][];
int N;
double F( int x, int y )
{
if( x<||y>=N )return -;
if( (x==&&y==) || (x==&&y==N-)
|| (x==N-&&y==) || (x==N-&&y==N-))return 2.0;
if( x== || y== || x==N- || y==N- ) return 3.0;
return 4.0;
}
int main( )
{
while(scanf("%d", &N)!= EOF){
double ans=;
if(N%==){
printf("%.4lf\n", ans);
continue;
}
memset(dp, , sizeof dp); dp[][N/][N/]=; for( int t=; t<N; ++ t ){
for( int i=; i<N; ++ i ){
for( int j=; j<N; ++ j ){
for(int k=; k<; ++ k){
int x=i+dir[k][], y=j+dir[k][];
if( F(x, y)> )
dp[t+][i][j]+=dp[t][x][y]/F(x,y);
}
if( i==N/ && j==t ){
ans+=dp[t+][i][j];
dp[t+][i][j]=;
}
}
}
}
printf("%.4lf\n", ans);
}
return ;
}

   

zoj 2271 Chance to Encounter a Girl <概率DP>的更多相关文章

  1. ZOJ 3329 One Person Game (经典概率dp+有环方程求解)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3329 题意:现在有三个骰子,分别有k1,k2和k3面,面上的点就是1~ki ...

  2. zoj 3822(概率dp)

    ZOJ Problem Set - 3822 Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Ju ...

  3. zoj 3822 Domination (概率dp 天数期望)

    题目链接 参考博客:http://blog.csdn.net/napoleon_acm/article/details/40020297 题意:给定n*m的空棋盘 每一次在上面选择一个空的位置放置一枚 ...

  4. zoj 3640 Help Me Escape 概率DP

    记忆化搜索+概率DP 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...

  5. ZOJ 3822 Domination(概率dp 牡丹江现场赛)

    题目链接:problemId=5376">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5376 Edward ...

  6. ZOJ 3822 Domination 概率dp 难度:0

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

  7. zoj 3822 Domination 概率dp 2014牡丹江站D题

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

  8. ZOJ 3822 ( 2014牡丹江区域赛D题) (概率dp)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5376 题意:每天往n*m的棋盘上放一颗棋子,求多少天能将棋盘的每行每列都至少有 ...

  9. [转]概率DP总结 by kuangbin

    概率类题目一直比较弱,准备把kuangbin大师傅总结的这篇题刷一下! 我把下面的代码换成了自己的代码! 原文地址:http://www.cnblogs.com/kuangbin/archive/20 ...

随机推荐

  1. Atcoder CODE FESTIVAL 2017 qual B C - 3 Steps 二分图

    题目链接 题意 给定一个无向图,\(n\)个点,\(m\)条边(\(n,m\leq 1e5\)). 重复如下操作: 选择相异的两点u,v满足从点u出发走三条边恰好能到达点v.在这样的u,v点对之间添一 ...

  2. IOS 改变Navigation的返回按钮

    两个办法: 1, 手动为每一个UIViewController添加navigationItem的leftButton的设置代码 2,为UINavigationController实现delegate, ...

  3. LeetCode OJ--Path Sum *

    https://oj.leetcode.com/problems/path-sum/ 树的深搜,求从根到叶子的路径. 记住深搜的样子 #include <iostream> using n ...

  4. 数据结构自己实现——queue

    SeqQueue.h #define QueueSize 100 typedef char DataType; class SeqQueue { public: DataType data[Queue ...

  5. Maven添加坐标(依赖)及在Eclipse中的操作

    例如:添加一个spring-test.jar的依赖过程,普遍的做法就是直接操作pom.xml文件. 1.打开maven的中央仓库:http://search.maven.org/ 2.搜索仓库: 进入 ...

  6. DBCC

    http://www.cnblogs.com/lyhabc/archive/2013/01/19/2867174.html http://www.cnblogs.com/lyhabc/articles ...

  7. Linux有问必答:如何检查Linux的内存使用状况

    -1. /proc/meminfo11% -2. atop20% -3. free29% -4. GNOME System Monitor35% -5. htop41% -6. KDE System ...

  8. tensorflow global_variables_initializer()

    老版本为 init = tf.initialize_all_variables() 新版本为 init = tf.global_variables_initializer()

  9. 开源软件许可认证:open softwae license

    OSIA认证的开放源代码软件的软件许可证有如下21种: 1.The GNU General Public License (GPL) 2.The GNU Library or "Lesser ...

  10. SilverLight:布局(2)GridSplitter(网格分割)垂直分割、水平分割

    ylbtech-SilverLight-Layout: 布局(2)GridSplitter(网格分割)垂直分割.水平分割 A, Splitter(分割)对象之 GridSplitter(网格分割)1: ...