HDU3853
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.
裸的期望DP
dp[i[j]表示当前在i,j位置,到达终点的期望
我们不难看出转移方程为
dp[i][j]=dp[i][j]*p0+dp[i][j+1]*p1+dp[i+1][j]*p2
解这个式子有两种方法
1.高斯消元
2.把右边的dp[i][j]除到左边
1 #include<iostream>
2 #include<cstring>
3 #include<cstdio>
4 #include<cstdlib>
5 #include<cmath>
6 using namespace std;
7 const int MAXN=2001;
8 const int INF=0x7fffff;
9 double dp[MAXN][MAXN];//走到i,j的期望
10 struct node
11 {
12 double a,b,c;
13 void clear(){a=b=c=0.0;}
14 }map[MAXN][MAXN];
15 int n,m;
16 const double eps=1e-5;
17 int main()
18 {
19 dp[n][m]=0;
20 while(scanf("%d%d",&n,&m)!=EOF)
21 {
22 memset(dp,0.00,sizeof(dp));
23 dp[n][m]=0;
24 for(int i=1;i<=n;i++)
25 for(int j=1;j<=m;j++)
26 map[i][j].clear();
27 for(int i=1;i<=n;i++)
28 for(int j=1;j<=m;j++)
29 scanf("%lf%lf%lf",&map[i][j].a,&map[i][j].b,&map[i][j].c);
30 for(int i=n;i>=1;i--)
31 for(int j=m;j>=1;j--)
32 {
33 if(i==n&&j==m) continue;
34 if(fabs(1.00-map[i][j].a)<eps) continue;
35 dp[i][j]=(map[i][j].b*dp[i][j+1]+map[i][j].c*dp[i+1][j]+2.00)/(1.0-map[i][j].a);
36 }
37 printf("%.3lfn",dp[1][1]);
38 }
39
40
41 return 0;
42 }
- ASP.NET Core中的依赖注入(4): 构造函数的选择与服务生命周期管理
- 通过Knockout.js + ASP.NET Web API构建一个简单的CRUD应用
- 自动驾驶车辆在2017年的七大光辉历史时刻
- 简单的实现Javascript的MVC
- 谷歌再出黑科技!人工智能模拟的人声和真人几乎难以分辨
- 【Scikit-Learn 中文文档】高斯混合模型 - 无监督学习 - 用户指南 | ApacheCN
- “E+单拼”组合域名eqi.com小六位结拍
- ASP.NET Core中的依赖注入(3): 服务的注册与提供
- 【Scikit-Learn 中文文档】使用 scikit-learn 介绍机器学习 | ApacheCN
- 哈萨比斯:2018年AI最大突破在生物或化学领域
- ASP.NET Core中的依赖注入(5): ServiceProvider实现揭秘 【总体设计 】
- ASP.NET MVC的View是如何被呈现出来的?[设计篇]
- Python大牛告诉你一行代码能干什么?神奇
- 谷歌最新人工智能研究:仅利用稀疏轮廓位置“重构”图像
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- SpringBoot 2.3.0 新特性一览,快来跟我实践一波!
- 【腾讯】在前端开发中,如何获取浏览器的唯一标识
- 如何实现表格单双行条纹样式
- Angular 容易忽略的知识点
- 语雀自动同步到hexo博客
- 推荐 3 款超好用的 Docker 图形化管理工具
- python标准库之glob介绍
- Python 为什么只需一条语句“a,b=b,a”,就能直接交换两个变量?
- 使用List中的remove方法遇到的坑,不信你没有踩过!
- python opencv 图像尺寸变换
- OpenCv保存图像
- 机器学习|KNN
- docker 查看容器日志
- consul配置ACL
- CentOS7.5更改python版本后及yum不能用的解决办法,非编译!