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 << "=" <
;< 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; }