Light OJ 1030 - Discovering Gold(機率dp)

來源:互聯網
上載者:User

標籤:pen   eof   sed   over   ++   exp   sizeof   block   scanf   

題目連結:http://www.lightoj.com/volume_showproblem.php?problem=1030

題目大意:有一個很長的洞穴, 可以看做是1-n的格子。你的起始位置在1的地方, 每個格子中都有價值為v[i]的寶藏。 有一個6面的骰子,數字為從1-6, 每次搖一次骰子, 得到的數字x後, 你可以到達距離當前位置大x的位置, 並且得到那個位置的寶藏。 如果要走的位置在n的外面, 那麼在此搖骰子, 直到找到一個合適的數字。到達n位置的時候結束。 現在想知道走到n位置的能夠獲得寶藏價值的期望。

代碼如下:從後往前推。

    #include<bits/stdc++.h>    using namespace std;         void solve(int _)    {        int n;        scanf("%d", &n);        int arr[105];        for(int i=1; i<=n; ++ i)            scanf("%d", &arr[i]);        double dp[105];        memset(dp, 0, sizeof(dp));        for(int i=n; i >= 1; -- i)        {            dp[i] += arr[i];            int t = min(n, i+6);            for(int j=i+1; j<=t; ++ j)                dp[i] += 1.0 / (t - i) * dp[j];        }        printf("Case %d: %.10f\n", _, dp[1]);    }         int main()    {        int n;        scanf("%d", &n);        for(int i=1; i<=n; ++ i)            solve(i);        return 0;    }     
View Code

 

Light OJ 1030 - Discovering Gold(機率dp)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.