HDU 3853 LOOPS 期望dp
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=3853
LOOPS
Time Limit: 15000/5000 MS (Java/Others)Memory Limit: 125536/65536 K (Java/Others)
#### 问题描述
> Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl).
>
> Homura wants to help her friend Madoka save the world. But because of the plot of the Boss Incubator, she is trapped in a labyrinth called LOOPS.
>
>
> The planform of the LOOPS is a rectangle of R*C grids. There is a portal in each grid except the exit grid. It costs Homura 2 magic power to use a portal once. The portal in a grid G(r, c) will send Homura to the grid below G (grid(r+1, c)), the grid on the right of G (grid(r, c+1)), or even G itself at respective probability (How evil the Boss Incubator is)!
> At the beginning Homura is in the top left corner of the LOOPS ((1, 1)), and the exit of the labyrinth is in the bottom right corner ((R, C)). Given the probability of transmissions of each portal, your task is help poor Homura calculate the EXPECT magic power she need to escape from the LOOPS.
输入
The first line contains two integers R and C (2 <= R, C <= 1000).
The following R lines, each contains C*3 real numbers, at 2 decimal places. Every three numbers make a group. The first, second and third number of the cth group of line r represent the probability of transportation to grid (r, c), grid (r, c+1), grid (r+1, c) of the portal in grid (r, c) respectively. Two groups of numbers are separated by 4 spaces.
It is ensured that the sum of three numbers in each group is 1, and the second numbers of the rightmost groups are 0 (as there are no grids on the right of them) while the third numbers of the downmost groups are 0 (as there are no grids below them).
You may ignore the last three numbers of the input data. They are printed just for looking neat.
The answer is ensured no greater than 1000000.
Terminal at EOF
输出
A real number at 3 decimal places (round to), representing the expect magic power Homura need to escape from the LOOPS.
样例输入
2 2
0.00 0.50 0.50 0.50 0.00 0.50
0.50 0.50 0.00 1.00 0.00 0.00
样例输出
6.000
题意
给你一个R*C的地图,你要从(1,1)走到(R,C),每次你可以选择留原地,或向下走一格,或向右走一格,问最后的
题解
和poj 2096一个意思。
代码
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<ctime>
#include<vector>
#include<cstdio>
#include<string>
#include<bitset>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
#define X first
#define Y second
#define mkp make_pair
#define lson (o<<1)
#define rson ((o<<1)|1)
#define mid (l+(r-l)/2)
#define sz() size()
#define pb(v) push_back(v)
#define all(o) (o).begin(),(o).end()
#define clr(a,v) memset(a,v,sizeof(a))
#define bug(a) cout<<#a<<" = "<<a<<endl
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define scf scanf
#define prf printf
typedef long long LL;
typedef vector<intVI;
typedef pair<int,intPII;
typedef vector<pair<int,intVPII;
const int INF=0x3f3f3f3f;
const LL INFL=0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-8;
const double PI = acos(-1.0);
//start----------------------------------------------------------------------
const int maxn=1010;
int R,C;
double pro[maxn][maxn][3];
double dp[maxn][maxn];
int main() {
while(scf("%d%d",&R,&C)==2){
for(int i=1;i<=R;i++){
for(int j=1;j<=C;j++){
for(int k=0;k<3;k++){
scf("%lf",&pro[i][j][k]);
}
}
}
for(int i=R;i>=1;i--){
for(int j=C;j>=1;j--){
if(i==R&&j==C){
dp[i][j]=0.0;
}else{
double p0=pro[i][j][0];
double p1=pro[i][j][1];
double p2=pro[i][j][2];
///注意有些点是黑洞,跳不出去的!
if(fabs(1-p0)<eps) continue;
dp[i][j]=(p1*dp[i][j+1]+p2*dp[i+1][j]+2)/(1-p0);
}
}
}
prf("%.3f\n",dp[1][1]);
}
return 0;
}
//end-----------------------------------------------------------------------
HDU 3853 LOOPS 期望dp的更多相关文章
- hdu 3853 LOOPS (概率dp 逆推求期望)
题目链接 LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Tota ...
- HDU 3853 LOOPS 概率DP入门
LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total Sub ...
- hdu 3853 LOOPS 概率DP
简单的概率DP入门题 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...
- HDU 3853 LOOPS 可能性dp(水
在拐~ #include <stdio.h> #include <cstring> #include <iostream> #include <map> ...
- HDU 3853 LOOPS:期望dp【网格型】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3853 题意: 有一个n*m的网格. 给出在每个格子时:留在原地.向右走一格,向下走一格的概率. 每走一 ...
- 【HDU3853】LOOPS [期望DP]
LOOPS Time Limit: 5 Sec Memory Limit: 64 MB[Submit][Status][Discuss] Description Akemi Homura is a ...
- hdu 3853 LOOPS(概率 dp 期望)
Problem Description Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl). Homura wants to help ...
- hdu 3853 LOOPS(基础DP求期望)
题目大意 有一个人被困在一个 R*C(2<=R,C<=1000) 的迷宫中,起初他在 (1,1) 这个点,迷宫的出口是 (R,C).在迷宫的每一个格子中,他能花费 2 个魔法值开启传送通道 ...
- HDU 3853 LOOP (概率DP求期望)
D - LOOPS Time Limit:5000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit St ...
随机推荐
- 使用java发送QQ邮件的总结
最近帮朋友做个网站,实现用邮箱订阅功能,所以现在把这个发送邮件的功能放在这里,算是这两天工作的总结吧! 首先,想要实现订阅功能,要把邮箱保存,但是这个做的是个小网站,前后台交互的太少了,所以我就直接保 ...
- 文字属性和div容器盒的使用基础
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 使用C语言给php写扩展
1.在php源码路径的ext文件夹下,新建一个extend_test.def文件,编辑文件内容为 string my_test_function(string str,int n) 2.在当前目录执行 ...
- Linux-2.6驱动程序分层分离概念
下面以一个按键的实验作为驱动分离时间简单学习: #include <linux/module.h> #include <linux/version.h> #include &l ...
- python新手第一天学习笔记-python循环控制和第一个python小游戏
Python的三种逻辑控制 1.python语法. python 是以缩进作为基本判断的.同一代码缩进需要保持一致.否则会报错 1.if 的三种循环 _age = 53 # 注意,input接受的都是 ...
- c#操作注册表的意外
因为要在C/S程序中使用WebBrowser控件,因为默认的IE版本很低,无法使用Html5功能,故需通过把程序名写入注册表的方法指定IE版本. 但操作的过程中出现一个问题: 1.使用代码找到相关项, ...
- 20155238 2016-2017-2 《Java程序设计》第一周学习总结
教材内容总结 浏览教材,根据自己的理解每章提出一个问题 1.Java语言跨平台的依据是什么?标准的出现是否会限制JAVA的开发与发展? 2.怎样理解类?PATH对于Java编写的意义是什么? 3.Ja ...
- 2017-2018-2 20155327『网络对抗技术』Exp5:MSF基础应用
2017-2018-2 20155327『网络对抗技术』Exp5:MSF基础应用 基础问题回答 用自己的话解释什么是exploit,payload,encode exploit:使用者利用漏洞进行攻击 ...
- 传统神经网络ANN训练算法总结
传统神经网络ANN训练算法总结 学习/训练算法分类 神经网络类型的不同,对应了不同类型的训练/学习算法.因而根据神经网络的分类,总结起来,传统神经网络的学习算法也可以主要分为以下三类: 1)前馈型神经 ...
- SSISDB2:SSIS工程的操作实例
SSISDB 系列随笔汇总: SSISDB1:使用SSISDB管理Package SSISDB2:SSIS工程的操作实例 SSISDB3:Package的执行实例 SSISDB4:当前正在运行的Pac ...