题目: 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. ubuntu16.04安装ibus中文输入法

    按照网上给的安装方法,没成功,在切换ibus的时候总是报错,记录下解决办法. 安装语言包 System Settings–>Language Support–>Install/Remove ...

  2. nVidia的物理系统

    PhysX PhysX(wiki en  中文,physx wiki   physx wiki2)是nVidia公司一款跨平台实时物理引擎,可使用硬件(GPU.PPU: Physics Process ...

  3. Ui大屏

    http://www.uimaker.com/plus/view.php?aid=128661&pageno=1

  4. 深入了解Entity Framework框架及访问数据的几种方式

    一.前言 1.Entity Framework概要 Entity Framework是微软以ADO.NET为基础所发展出来的对象关系映射(O/R Mapping)解决方案.该框架曾经为.NET Fra ...

  5. 2017-10-29-afternoon-清北模拟赛

    T1 洗澡 贪心:将未匹配的右括号花费1变为左括号,最有多余的左括号有一半变成右括号 #include <cstring> #include <cstdio> ); int n ...

  6. Ural 1774 Barber of the Army of Mages 最大流

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1774 1774. Barber of the Army of Mages Time li ...

  7. 项目心得——按照指定的日期/时间创建Date对象

    项目心得——按照指定的日期/时间创建Date对象 有时,在做项目中,需要获得指定日期的Date对象,这个指定的日期或者时间可能不是当前的时间.下面讲解两种获取指定日期/时间的Date对象的方法: pa ...

  8. mybatis 源码学习(二)sqlsession

    mybatis 中的sqlsession是一个非常重要的类.上篇我们分析了sessionfactory初始化配置文件,我们继续分析sessionfactory拿到会话进行的操作. 看这里.getMap ...

  9. [java基础] 001 - 记一次堆栈溢出异常(StackOverFlowError)

    上午经理发来一个任务,解决某个接口异常,此接口第一次调用成功返回: {ret=Y, orderResultList=[{itemno=31920190521083622032, sub_msg=成功, ...

  10. Openlayers3 编辑要素

    参考文章 Openlayers之编辑要素 MAPZONE GIS SDK接入Openlayers3之五——图形编辑工具 [学习笔记之Openlayers3]要素保存篇(第四篇) openlayers实 ...