zoukankan      html  css  js  c++  java
  • HDU_3853_概率dp

    http://acm.hdu.edu.cn/showproblem.php?pid=3853

    又因为总期望为子期望的加权和,加权因子为子期望的转移概率,所以得到:
    dp[ i ][ j ]= p1 * ( dp[ i ][ j ] + 2 ) + p2 * ( dp[ i ][ j + 1 ] + 2 ) + p3 * ( dp[ i + 1 ][ j ] + 2) 。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    
    int c,r;
    double ans[1005][1005],stay[1005][1005],rightt[1005][1005],down[1005][1005];
    
    int main()
    {
        while(~scanf("%d%d",&r,&c))
        {
            memset(ans,0,sizeof(ans));
            for(int i = 1;i <= r;i++)
            {
                for(int j = 1;j <= c;j++)   scanf("%lf%lf%lf",&stay[i][j],&rightt[i][j],&down[i][j]);
            }
            for(int i = r;i >= 1;i--)
            {
                for(int j = c;j >= 1;j--)
                {
                    if(-1e-6 <= stay[i][j]-1 && stay[i][j]-1 <= 1e-6)   continue;
                    ans[i][j] = (2+rightt[i][j]*ans[i][j+1]+down[i][j]*ans[i+1][j])/(1-stay[i][j]);
                }
            }
            printf("%.3f
    ",ans[1][1]);
        }
        return 0;
    }
  • 相关阅读:
    移动网络优化
    移动网络架构与数据传输
    移动网络简介与RRC
    CSS之外边距折叠
    网络协议之TLS
    Smarty 模板引擎简介
    FormData介绍
    相对路径与绝对路径
    OAuth2.0
    Redis学习手册(List数据类型)
  • 原文地址:https://www.cnblogs.com/zhurb/p/5890698.html
Copyright © 2011-2022 走看看