hdu 3853 概率dp
来源:互联网 发布:淘宝卖死人衣服视频 编辑:程序博客网 时间:2024/06/03 15:46
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.
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 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
2 20.00 0.50 0.50 0.50 0.00 0.500.50 0.50 0.00 1.00 0.00 0.00
6.000
题意:求从(1, 1)点走到(n, m)点的花费能量的期望, 每次决策消耗2点能量。 每次可以原地不动或者向右或者向下, 分别有个概率。
思路:运用全概率期望公式, d[i][j] = a[1]*d[i][j] + a[2]*d[i+1][j] + a[3]*d[i][j+1] + 2, 其中a[i]是三个可能情况的概率。 因为dp方程要满足无后效性, 所以移项得d[i][j] = (2 + a[2]*d[i+1][j] + a[3]*d[i][j+1]) / (1 - a[i][j])。
ac代码:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;struct node{ double s,l,r;}data[1005][1005];double dp[1005][1005];int main(){ int l,r; while(cin>>l>>r) { for(int i=1;i<=l;i++) { for(int j=1;j<=r;j++) scanf("%lf%lf%lf",&data[i][j].s,&data[i][j].l,&data[i][j].r); } memset(dp,0,sizeof(dp)); for(int i=l;i>=1;i--) { for(int j=r;j>=1;j--) { if(i==l&&j==r) continue; if(data[i][j].s==1.0) continue; dp[i][j]=(dp[i+1][j]*data[i][j].r+dp[i][j+1]*data[i][j].l+2)/(1.0-data[i][j].s); } } printf("%.3lf\n",dp[1][1]); //cout<<dp[1][1]<<endl; } return 0;}
阅读全文
0 0
- hdu 3853 概率DP
- HDU 3853 概率DP
- HDU 3853 概率DP
- HDU 3853 概率dp
- 概率dp HDU 3853
- hdu 3853 概率dp
- HDU 3853 概率dp
- hdu 3853 概率dp
- hdu 3853 LOOPS 概率dp
- HDU 3853 LOOPS (概率DP)
- HDU 3853 LOOPS (概率dp)
- HDU 3853 LOOPS(概率dp)
- hdu-3853-LOOPS-概率dp
- HDU 3853 LOOPS(概率dp)
- hdu 3853 概率DP 简单
- hdu 3853 LOOPS 概率dp
- hdu 3853 LOOPS (概率dp)
- HDU 3853 期望概率DP
- HDFS
- 第32讲:异常处理:你不可能总是对的
- Initialization failed for 'https://start.spring.io' Please check URL, network and proxy settings.
- HttpURLConnection网络获取
- 超级详细的MyEclipse安装教程!
- hdu 3853 概率dp
- mapreduce
- Java并发包-浅析LongAdder
- App跨平台开发框架分析
- 51 nod 循环最大字段和 DP
- java1.8版本hashTable源码阅读
- 动作、按键
- 【WEB】百度糯米学院学习笔记
- HTML5 Web 存储