题目: 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. DevExpress GridControl 控件点滴

    一.常用控件样式 public void setDgv(DevExpress.XtraGrid.Views.Grid.GridView gridView1) { gridView1.OptionsVi ...

  2. CodeForces 97D. Robot in Basement

    time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standa ...

  3. 【CF1029A】Many Equal Substrings(模拟)

    题意:给定一个长度为n的串s,要求构造一个长度最小的使s出现了k次的串,可以重叠 n<=50,k<=50 思路:计算一下前后缀相同长度 #include<cstdio> #in ...

  4. XOCDE5开发

    一.XCODE5以后,file's owner取消,那么table view的数据源和委托应该指向哪里呢,答案是指向view control那里,当然了,view control必须与相应继承了数据源 ...

  5. [转]iOS7 后台执行

    [转自:http://esoftmobile.com/2013/06/23/ios7%E7%A8%8B%E5%BA%8F%E5%90%8E%E5%8F%B0%E8%BF%90%E8%A1%8C/] i ...

  6. 推荐!手把手教你使用Git(转)

    原文出处: 涂根华的博客   欢迎分享原创到伯乐头条 一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. 二:SVN与Git的最主要的区别? SVN是集中式版本控制系统,版本库是集中放 ...

  7. (1)angularJs

    一. 1.下载 https://angularjs.org/ 2.网络引用 https://code.angularjs.org/ 3.模块内引用 angularjs <body ng-app& ...

  8. 死磕 java同步系列之AQS起篇

    问题 (1)AQS是什么? (2)AQS的定位? (3)AQS的实现原理? (4)基于AQS实现自己的锁? 简介 AQS的全称是AbstractQueuedSynchronizer,它的定位是为Jav ...

  9. 洛谷—— P1134 阶乘问题

    https://www.luogu.org/problemnew/show/P1134 题目描述 也许你早就知道阶乘的含义,N阶乘是由1到N相乘而产生,如: 12! = 1 x 2 x 3 x 4 x ...

  10. HDU4372 Buildings

    @(HDU)[Stirling數, 排列組合] Problem Description There are N buildings standing in a straight line in the ...