Topic links
Test instructions
In a 1 X N grid, each lattice has a certain amount of gold, you start from the first lattice, ask the last lattice to get the gold expectations.
Each advance using a dice point to determine the number of steps forward, if the point of the cast will be more than N, then re-throw.
Ideas:
A very direct expectation problem.
The probability DP is expected from the forward, the probability of each time is 1/6.
Dp[i] = 1/6 * (dp[i + 1] + Dp[i + 2] + Dp[i + 3] + Dp[i + 4] + Dp[i + 5] + Dp[i + 6]) + x[i].
Depending on the number of points thrown plus whether the current position will exceed N to determine the added item in parentheses, there is a probability.
Code:
1#include <cmath>2#include <cstdio>3#include <cstring>4#include <cstdlib>5#include <ctime>6#include <Set>7#include <map>8#include <list>9#include <queue>Ten#include <string> One#include <vector> A#include <fstream> -#include <iterator> -#include <iostream> the#include <algorithm> - using namespacestd; - #defineLL Long Long - #defineMAXN 110 + #defineMOD 1000000007 - #defineEPS 1e-6 + intN; A DoubleDP[MAXN]; at - intMain () - { - intT; - intKcase =0; -scanf"%d", &T); in while(T--) - { toscanf"%d", &n); + for(inti =1; I <= N; i + +) -scanf"%LF", &dp[i]); the for(inti = n-1; I >=1; I--) * { $ if((n-i) >=6)Panax Notoginseng for(intj =1; J <=6; J + +) -Dp[i] + = Dp[i + j]/6.0; the Else + for(intj =1; J <= (N-i); J + +) ADp[i] + = Dp[i + j]/(Double) (N-i); the } +printf"Case %d:%.7lf\n", + + kcase, dp[1]); - } $ return 0; $}
View Code
lightoj_1030 Discovering Gold