zoukankan      html  css  js  c++  java
  • hdu 3853 概率dp

                                                             LOOPS

    Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)
    Total Submission(s): 3738    Accepted Submission(s): 1488


    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.




     
    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


     
    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 2 0.00 0.50 0.50 0.50 0.00 0.50 0.50 0.50 0.00 1.00 0.00 0.00
     
    Sample Output
    6.000
     
    Source
     
    题意:在N*M的图里,对于每个点,给你向下或者向右不动的概率,问你从0,0到n,m的期望
    题解:dp[i][j]表示从(i,j)到(n,m)的期望大小
    dp[i][j]=p2[i][j]*dp[i][j+1]/(1-p1[i][j])+p3[i][j]*dp[i+1][j]/(1-p1[i][j])+2/(1-p1[i][j]);

    ///1085422276
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<queue>
    #include<cmath>
    #include<map>
    #include<bitset>
    #include<set>
    #include<vector>
    using namespace std ;
    typedef long long ll;
    #define push_back pb
    #define mem(a) memset(a,0,sizeof(a))
    #define TS printf("111111
    ");
    #define FOR(i,a,b) for( int i=a;i<=b;i++)
    #define FORJ(i,a,b) for(int i=a;i>=b;i--)
    #define READ(a,b) scanf("%d%d",&a,&b)
    #define mod 1000000007
    #define inf 100000
    #define maxn 1001
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //******************************************************************
    int n,m;
    double p1[maxn][maxn],p2[maxn][maxn],p3[maxn][maxn];
    double dp[maxn][maxn];
    int main()
    {
        while(READ(n,m)!=EOF)
        {
               FOR(i,0,n-1)
               FOR(j,0,m-1)
                   scanf("%lf%lf%lf",&p1[i][j],&p2[i][j],&p3[i][j]);
               mem(dp);
               FORJ(i,n-1,0)
               FORJ(j,m-1,0)
               {
                  if(i==n-1&&j==m-1){continue;}
                  if(p1[i][j]==1)dp[i][j]=0;
                  else
                  dp[i][j]=p2[i][j]*dp[i][j+1]/(1-p1[i][j])+p3[i][j]*dp[i+1][j]/(1-p1[i][j])+2/(1-p1[i][j]);
               }
             printf("%.3f
    ",dp[0][0]);
        }
        return 0;
    }
    代码


  • 相关阅读:
    Andrew Ng机器学习week4(Neural Networks: Representation)编程习题
    linux系统下crontab 配置启动定时任务
    在python中配置tornado服务
    在python中Flask配置服务
    ltp的使用
    查看文件内容- 删除某个运行程序的所有进程-nohup后台执行程序
    机器学习和深度学习资料整理
    配置linux服务器和pycharm的连接
    计算 24 点是一种扑克牌益智游戏,随机抽出 4 张扑克牌,通过加 (+) ,减 (-) ,乘 ( * ), 除 (/) 四种运算法则计算得到整数 24 ,本问题中,扑克牌通过如下字符或者字符串表示,其中,小写 joker 表示小王,大写 JOKER 表示大王:
    机器人的运动范围 剑指offer66题
  • 原文地址:https://www.cnblogs.com/zxhl/p/4781635.html
Copyright © 2011-2022 走看看