Lightoj 1030-discovering Gold (expected DP)

Source: Internet
Author: User

Test instructions

Throw a dice, assuming that the positive upward value is x, the current position is I, each walk min (x,n−i) step, each to a lattice will get the corresponding gold number, to go through the length of the lattice of N to get gold's expectation of throwing a dice, assuming positive upward value of x, the current position is I, each walk min (x,n -i) step, each to a lattice will get the corresponding gold number, to go through the length of N lattice to get gold expectations

Analysis:

dp[i]:= to I lattice get the expectation of gold, and then transfer just fine dp[i]:= to I lattice to get the gold expectation, and then transfer just fine

Code:

Created by Taosama on 2015-11-02//Copyright (c) Taosama.
All rights reserved. #pragma COMMENT (linker, "/stack:1024000000,1024000000") #include <algorithm> #include <cctype> # Include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip > #include <iostream> #include <map> #include <queue> #include <string> #include <set> #
Include <vector> using namespace std; #define PR (x) cout << #x << "=" << x << "" #define PRLN (x) cout << #x << "=" &lt

;< x << Endl const int N = 1e5 +, INF = 0x3f3f3f3f, MOD = 1e9 + 7;
int n, a[105];

Double dp[105];
    Double dfs (int p) {double& ret = dp[p];
    if (Ret >= 0) return ret;
    if (p = = N) return a[n];
    ret = 0;
    int to = min (6, n-p);
    for (int i = 1; i <= to; ++i) ret + = DFS (p + i);
    ret = ret/to + a[p];
return ret; } int main () {#ifdef LOCAL freopen ("C:\\users\\taosama\\desktop\\in.txt", "R", stdin);
Freopen ("C:\\users\\taosama\\desktop\\out.txt", "w", stdout);

    #endif ios_base::sync_with_stdio (0); int t;
    scanf ("%d", &t);
    int kase = 0;
        while (t--) {scanf ("%d", &n);
        for (int i = 1; I <= n; ++i) scanf ("%d", A + i);
        for (int i = 1; I <= n; ++i) dp[i] = 1;
    printf ("Case%d:%.12f\n", ++kase, DFS (1));
} return 0; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.