HDOJ 题目3853 LOOPS(概率DP)
来源:互联网 发布:平面图纸制作软件 编辑:程序博客网 时间:2024/06/05 10:46
LOOPS
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total Submission(s): 3889 Accepted Submission(s): 1550
Problem Description
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.
Input
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
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
Output
A real number at 3 decimal places (round to), representing the expect magic power Homura need to escape from the LOOPS.
Sample Input
2 20.00 0.50 0.50 0.50 0.00 0.500.50 0.50 0.00 1.00 0.00 0.00
Sample Output
6.000
Source
2011 Invitational Contest Host by BUPT
Recommend
chenyongfu | We have carefully selected several similar problems for you: 3857 3854 3849 3850 3851
题目大意:从1 1点走到n m点,给出每个点停留在原地,向右走向下走的概率,每走一步消耗2点,问走到n m点消耗的期望
ac代码
152077352015-10-22 21:35:04Accepted38533276MS33416K1039 BC++Who_you?
#include<stdio.h>#include<string.h>#include<math.h>#include<iostream>#include<algorithm>using namespace std;double p[1010][1010][3],dp[1010][1010];int n,m;void init(){ int i,j; for(i=0;i<=n;i++) for(j=0;j<=m;j++) dp[i][j]=-1.0;}int main(){ // int n,m; while(scanf("%d%d",&n,&m)!=EOF) { int i,j,k; for(i=1;i<=n;i++) for(j=1;j<=m;j++) for(k=0;k<3;k++) scanf("%lf",&p[i][j][k]); // init(); memset(dp,0,sizeof(dp)); for(i=n;i>0;i--) for(j=m;j>0;j--) { //if(dp[i][j]==-1.0) // continue; if(p[i][j][0]==1.0) continue; if(i==n&&j==m) continue; dp[i][j]=(p[i][j][1]*dp[i][j+1]+dp[i+1][j]*p[i][j][2]+2)/(1.0-p[i][j][0]); // printf("%.3lf\n",dp[i][j]); } printf("%.3lf\n",dp[1][1]); }}
0 0
- HDOJ 题目3853 LOOPS(概率DP)
- HDOJ 3853 LOOPS (概率DP)
- HDOJ-3583LOOPS(概率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 LOOPS (概率DP)
- hdu 3853 LOOPS(概率dp)
- HDOJ 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 LOOPS(概率dp)
- NSOperation的基本使用——本质是对GCD的封装
- App竞品技术分析 序言
- 中科院自动化所彭思龙,相见恨晚啊
- Visual studio属性配置中可以使用到的一些宏
- 贴吧抓数据
- HDOJ 题目3853 LOOPS(概率DP)
- Children of the Candy Corn(dfs+bfs)
- App竞品技术分析 (1)App启动速度
- 1029. Median
- GCD实践——信号量
- Objective-C语法之代码块(block)的使用
- 关于MySQL的dos客户端中文插入和显示utf-8乱码的解决方法
- Hello World!
- App竞品技术分析 (2)Html5页面的打开速度