zoj 2271 Chance to Encounter a Girl <概率DP>
题目: 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>的更多相关文章
- ZOJ 3329 One Person Game (经典概率dp+有环方程求解)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3329 题意:现在有三个骰子,分别有k1,k2和k3面,面上的点就是1~ki ...
- zoj 3822(概率dp)
ZOJ Problem Set - 3822 Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Ju ...
- zoj 3822 Domination (概率dp 天数期望)
题目链接 参考博客:http://blog.csdn.net/napoleon_acm/article/details/40020297 题意:给定n*m的空棋盘 每一次在上面选择一个空的位置放置一枚 ...
- zoj 3640 Help Me Escape 概率DP
记忆化搜索+概率DP 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...
- ZOJ 3822 Domination(概率dp 牡丹江现场赛)
题目链接:problemId=5376">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5376 Edward ...
- ZOJ 3822 Domination 概率dp 难度:0
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- zoj 3822 Domination 概率dp 2014牡丹江站D题
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- ZOJ 3822 ( 2014牡丹江区域赛D题) (概率dp)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5376 题意:每天往n*m的棋盘上放一颗棋子,求多少天能将棋盘的每行每列都至少有 ...
- [转]概率DP总结 by kuangbin
概率类题目一直比较弱,准备把kuangbin大师傅总结的这篇题刷一下! 我把下面的代码换成了自己的代码! 原文地址:http://www.cnblogs.com/kuangbin/archive/20 ...
随机推荐
- Spring入门 (IOC)
1.实现原理
- 【MFC】MFC中使对话框变成圆角矩形的代码(转)
原文转自 http://blog.csdn.net/cracent/article/details/48274469 BOOL CLoginDlg::OnInitDialog() { CDialog: ...
- 子进程wait参数详解
os模块的简介参看 Python::OS 模块 -- 简介 os模块的文件相关操作参看 Python::OS 模块 -- 文件和目录操作 os模块的进程参数 Python::OS 模块 -- 进程参数 ...
- 不要使用 reader.Peek() 去读取每行数据
1.问题描述 使用SteamRead的Peek()和ReadLine()来读取流中的数据,如果数据行数太多,会读取不完整(后面有些数据就读不出来了). 比如: while (srResponseRea ...
- 详解webpack-dev-server的配置属性
1.devServer.contentBase 它指定了服务器资源的根目录,如果不写入contentBase的值,那么contentBase默认是项目的目录. 在上面例子中产生错误和后来解决错误的 ...
- Web前端入门知识
第一阶段:理论知识 第一章:协议理解 第二阶段:了解知识 第二章:前端简介 第三阶段:入门知识 第三章:标签结构 第四章:常用标签 第四阶段:样式搭配 第五章:样式初见 第六章:属性选择 第七章:属性 ...
- 洛谷——P1988 火炬
P1988 火炬 题目描述 2008北京奥运会,你想成为四川汶川的一名火炬手,经过层层选拔,终于到了最后一关,这一关是一道很难的题:任意给定一个正整数N(N<=100000),求一个最小的正整数 ...
- Jenkins-------初探
Jenkins 安装和使用就不说了,说一下jenkins mail的配置,稍微有点坑,记住两个地址一致 插件安装时也出问题,大天朝的防火墙真是醉了,如下 更换我大天朝的镜像站 链接如下 ht ...
- OpenGL step to step(1)
在窗体上绘制一个矩形,just a demo #include <GLUT/GLUT.h> void init() { glClearColor(0.0,0.0,0.0,0.0); glS ...
- GOF23种设计模式-工厂模式
• 工厂模式: – 实现了创建者和调用者的分离. – 详细分类: • 简单工厂模式 • 工厂方法模式 • 抽象工厂模式 • 面向对象设计的基本原则: – OCP(开闭原则,Open-Closed Pr ...