zoukankan      html  css  js  c++  java
  • HDU 4405 Aeroplane chess 概率DP 难度:0

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

    明显,有飞机的时候不需要考虑骰子,一定是乘飞机更优

    设E[i]为分数为i时还需要走的步数期望,j为某个可能投出的点数如果从i向i-j推导,我们并不能确定i的转移方向,因为可能有两个i-j有飞机其目的地是i,所以我们选择从i向i+j推导期望

    如果设G[i]为分数为i时已经走过的步数期望,那么要确定G[i+j]需要知道P(i|i+j),也即转移到i+j的条件下从i转移来的概率,比较麻烦

    由题意,设match[i]为i处飞机的目的地,则当match[i]存在时,E[i]=E[match[i]],否则E[i]=sigma((E[i+j]+1)*(1/6)),j in range(6)

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    const int maxn=1e5+5;
    double e[maxn];
    int match[maxn];
    int n,m;
    void init()
    {
        memset(e,0,sizeof(e));
        memset(match,0,sizeof(match));
        for(int i=0;i<m;i++){
            int f,t;
            scanf("%d%d",&f,&t);
            match[f]=t;
        }
    }
    int lt(int a){return min(a,n);}
    void calc()
    {
        for(int i=n-1; i>=0; i--)
        {
            if(match[i]!=0)e[i]=e[lt(match[i])];
            else
            {
                for(int j=1; j<=6; j++)
                {
                    e[i]+=(e[lt(i+j)]+1)/6;
                }
            }
        }
    }
    int main()
    {
        for(int ti=1; scanf("%d%d",&n,&m)==2&&(n||m); ti++)
        {
            init();
            calc();
            printf("%.4f
    ",e[0]);
        }
    
        return 0;
    }
    
  • 相关阅读:
    Centos7 定时任务
    Linux启动配置文件和运行等级runlevel
    Linux 网卡命名规则
    将博客搬至CSDN
    Lua调用C++动态链接库.so
    使用shell脚本执行批量mongosh语句
    TCP和UDP详解
    经受时延的确认(Delay ACK)
    18张图带你了解衡量网络性能的四大指标:带宽、时延、抖动、丢包
    TCP学习
  • 原文地址:https://www.cnblogs.com/xuesu/p/4479638.html
Copyright © 2011-2022 走看看