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 ...
随机推荐
- DispatcherServlet与ContextLoaderListener的对比
1. 从DispatcherServlet和ContextLoaderListener的初始化过程可以看出,二者分别会生成一个WebApplicationContext,且以不同的attrName注册 ...
- QBXT 二月五号整理
给你一列数, 询问和最大的子串. N<=10^6 // N <=10^6 #include<cstdio> #include<iostream> using nam ...
- watch watch watch the video! I got almost addicted. Oh what a fuck!!!!
http://v.huya.com/play/574329.html#relate_vid=570467
- Linux--内核Uevent事件机制 与 Input子系统【转】
转自:http://blog.csdn.net/lxl584685501/article/details/46379453 [-] 一Uevent机制 Uevent在kernel中的位置 Uevent ...
- js-页面需展示大量图片时,采用lyz.delayLoading.min.js,图片在屏幕时加载显示
本文本内容拷贝至:https://blog.csdn.net/xuanwuziyou/article/details/48199123 当一个网页中有大量图片时,浏览器会逐个去下载这些图片,等全部下载 ...
- 洛谷—— P1873 砍树
https://www.luogu.org/problemnew/show/P1873 题目描述 伐木工人米尔科需要砍倒M米长的木材.这是一个对米尔科来说很容易的工作,因为他有一个漂亮的新伐木机,可以 ...
- 某考试 T3 bitboard
bitboardDiscription 天才发明家小K 制造了一块比特板.板子上有2^n个比特元,编号为0 ∼ 2^n−1.每个比特元
- 结构体和类中属性定义需要static地方
private function Readxxx:Integer;static; public class property XXX:Integer read ReadXXx; Txxx =recor ...
- Oracle 11g客户端
资源 下载资源,直接解压进行配置 Oracle官方资源:http://www.oracle.com/technetwork/database/features/instant-client/index ...
- Python 自动登录网站(处理Cookie)
http://digiter.iteye.com/blog/1300884 Python代码 def login(): cj = cookielib.CookieJar() ope ...