HDU 3853 LOOPS
题意:对于每一格,都可以往右走,原地不走,往下走,概率分别为a[i],b[i],c[i](每一个格子与其他格子的概率不一定相同)。在R*C的棋盘上(输入数据保证不会走出棋盘),求从(0, 0)走到(R-1, C-1)所需要的步数*2的期望是多少。
解法:就是最普通的dp,从(R-1, C-1)往(0, 0)算就好。设dp[i][j]表示达到目标状态的步数期望*2。dp[i][j] = dp[i][j]*a[k] + dp[i][j+1]*b[k] + dp[i+1][j]*c[k]。注意,如果a[k]= 1,应该直接dp[i][j] = 0; continue。
tag: 概率DP, 水题
/*
* Author: Plumrain
* Created Time: 2013-11-07 23:13
* File Name: DP-HDU-3853.cpp
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath> using namespace std; #define CLR(x) memset(x, 0, sizeof(x))
const double eps = 1e-;
struct grd{
double p[], x[];
}; int r, c;
grd a[][];
double d[][]; void init()
{
for (int i = ; i < r; ++ i)
for (int j = ; j < c; ++ j)
for (int k = ; k < ; ++ k)
scanf ("%lf", &a[i][j].p[k]);
} double DP()
{
CLR (d);
for (int i = r-; i >= ; -- i)
for (int j = c-; j >= ; -- j)
if (!(i == r- && j == c-)){
if (fabs(a[i][j].p[] - ) < eps) continue;
d[i][j] = (d[i][j+]*a[i][j].p[] + d[i+][j]*a[i][j].p[] + ) / ( - a[i][j].p[]);
}
return d[][];
} int main()
{
while (scanf ("%d%d", &r, &c) != EOF){
init();
printf ("%.3lf\n", DP());
}
return ;
}
HDU 3853 LOOPS的更多相关文章
- HDU 3853 LOOPS 期望dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3853 LOOPS Time Limit: 15000/5000 MS (Java/Others)Me ...
- HDU 3853 LOOPS:期望dp【网格型】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3853 题意: 有一个n*m的网格. 给出在每个格子时:留在原地.向右走一格,向下走一格的概率. 每走一 ...
- hdu 3853 LOOPS(概率 dp 期望)
Problem Description Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl). Homura wants to help ...
- 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 逆推求期望)
题目链接 LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Tota ...
- hdu 3853 LOOPS(基础DP求期望)
题目大意 有一个人被困在一个 R*C(2<=R,C<=1000) 的迷宫中,起初他在 (1,1) 这个点,迷宫的出口是 (R,C).在迷宫的每一个格子中,他能花费 2 个魔法值开启传送通道 ...
- 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.split.hdu.edu.cn/showproblem.php?pid=3853 LOOPS Problem Description Akemi Homura is a M ...
随机推荐
- 在一个UIView中如何使用多个UIPickerView
可以现在storyboard的UIView中拖入多个UIPickerView 然后同样是继承相关的UIPickerView协议 <UIPickerViewDataSource,UIPickerV ...
- uva 10934 Dropping water balloons(转载)
本文转载自http://blog.csdn.net/shuangde800/article/details/11273123 题意 你有k个一模一样的水球,在一个n层楼的建筑物上进行测试,你想知道水球 ...
- xml文件中 android:showAsAction = " " 的作用
在xml文件中设置android:showAsAction = " "有什么作用呢 安卓开发项目文件中有一个目录叫做menu,里面有main.xmlitem选项里有一句 andro ...
- C#解leetcode 152. Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- left ,right ,cross ,full/left outer join/区别 详解
--创建测试表wwif OBJECT_ID('qq') is not null drop table qqcreate table qq([序号] varchar(5),[内容1] varchar(1 ...
- Rechability的简单使用
AppDelegate.m #import "AppDelegate.h" #import "Reachability.h" @interface AppDel ...
- C++ 数组作为函数参数时,传递数组大小的方法
废话不多说,先上错误示范: void fun(int arr[arr_num]) { // ... } int main() { // ... int *arr = new int[10]; fun( ...
- _Obj* __STL_VOLATILE* __my_free_list
今天在读<STL源码剖析>空间配置器第二级时看到了这句,有点不解,于是查阅后知: obj后面是个指针 STL_VOLATILE也应该是个类型定义的吧,程序中应该有define来对它定义.所 ...
- 你好,C++(32) 类是对现实世界的抽象和描述 6.2.1 类的声明和定义
6.2 类:当C++爱上面向对象 类这个概念是面向对象思想在C++中的具体体现:它既是封装的结果,同时也是继承和多态的载体.因此,要想学习C++中的面向对象程序设计,也就必须从“类”开始. 6.2. ...
- 08_linux下安装chrome
首先下载chrome,需要改hosts哦(o(^▽^)o,别告诉我你不会,可以问度娘.谷哥哦) 下载地址:https://dl.google.com/linux/direct/google-chrom ...