到达终点的指望,到达顶峰的指望

Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl).

Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl).

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.

图片 1

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("%.3lf\n",dp[1][1]);
38     }
39     
40     
41     return 0;
42 }

 

http://www.bkjia.com/cjjc/1231925.htmlwww.bkjia.comtruehttp://www.bkjia.com/cjjc/1231925.htmlTechArticleHDU3853, 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 t…

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.

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.

图片 2

图片 3

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 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

dp[i[j]代表最近在i,j地方,到达终点的盼望

dp[i[j]代表近来在i,j地方,到达极限的想望

咱俩简单看出转移方程为

大家简单看出转移方程为

$dp[i][j]=dp[i][j]*p0+dp[i][j+1]*p1+dp[i+1][j]*p2$

$dp[i][j]=dp[i][j]*p0+dp[i][j+1]*p1+dp[i+1][j]*p2$

解这么些姿势有三种情势

解这几个姿势有三种办法

1.高斯消元

1.高斯消元

2.把左侧的$dp[i][j]$除到左边

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("%.3lf\n",dp[1][1]);
38     }
39     
40     
41     return 0;
42 }
 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("%.3lf\n",dp[1][1]);
38     }
39     
40     
41     return 0;
42 }

 

 

相关文章