zoukankan      html  css  js  c++  java
  • LightOJ-1030-Discovering Gold

    链接:

    https://vjudge.net/problem/LightOJ-1030

    题意:

    You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell of the cave can contain any amount of gold.

    Initially you are in position 1. Now each turn you throw a perfect 6 sided dice. If you get X in the dice after throwing, you add X to your position and collect all the gold from the new position. If your new position is outside the cave, then you keep throwing again until you get a suitable result. When you reach the Nth position you stop your journey. Now you are given the information about the cave, you have to find out the expected number of gold you can collect using the given procedure.

    思路:

    DP[i] 表示从i点往n点走的期望值,考虑从某点开始时可以直接拿走对应的黄金。
    同时i点往前延伸min(6, n-i)个点都是有概率走到的,直接计算期望。

    代码:

    #include <iostream>
    #include <memory.h>
    #include <string>
    #include <istream>
    #include <sstream>
    #include <vector>
    #include <stack>
    #include <algorithm>
    #include <map>
    #include <queue>
    #include <math.h>
    #include <cstdio>
    #include <set>
    #include <iterator>
    #include <cstring>
    #include <assert.h>
    using namespace std;
    
    typedef long long LL;
    
    double Dp[110];
    int a[110];
    int n;
    
    int main()
    {
        int t, cnt = 0;
        scanf("%d",&t);
        while (t--)
        {
            memset(Dp, 0, sizeof(Dp));
            scanf("%d", &n);
            for (int i = 1;i <= n;i++)
                scanf("%d", &a[i]);
            Dp[n] = a[n];
            for (int i = n-1;i >= 1;i--)
            {
                Dp[i] += a[i];
                int step = min(6, n-i);
                for (int j = 1;j <= step;j++)
                    Dp[i] += (1.0/step)*Dp[i+j];
            }
            printf("Case %d: %.7lf
    ", ++cnt,  Dp[1]);
        }
    
        return 0;
    }
    
  • 相关阅读:
    preventDefault
    YII2中的Html助手和Request组件
    yii2 输出json的方法
    FormData异步上传
    通过Ajax方式上传文件,使用FormData进行Ajax请求
    Yii设置Cache缓存的方法
    exif_imagetype() 函数在linux下的php中不存在
    Thinkphp整合各个功能
    PHP cURL库函数抓取页面内容
    javascript实现打印功能
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11448526.html
Copyright © 2011-2022 走看看