The main idea: a person to go to the end of N lattice. Use the dice to determine how many steps you take. Each lattice has gold, asking for the final amount of gold to be expected.
Suppose Dp[i] is the probability to the first lattice.
A[i] for the number of gold in the first lattice.
Then hope is σa[i]*dp[i]
The point is how to find probabilities.
Take a sample example.
3
3 6 9
Dp[1]=1: No problem.
dp[2]=0.5
Dp[3]=dp[1]*0.5+dp[2]*1=1
/************************************************author:guanjuncreated TIME:2016/7/9 23:17:57File name:1 030.cpp*************************************************/#include<iostream>#include<cstring>#include<cstdlib>#include<stdio.h>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<math.h>#include<stdlib.h>#include<iomanip>#include<list>#include<deque>#include<stack>#defineull unsigned long Long#definell Long Long#defineMoD 90001#defineINF 0x3f3f3f3f#defineMAXN 10010#defineCLE (a) memset (A,0,sizeof (a))Constull inf = 1LL << A;Const Doubleeps=1e-5;using namespaceStd;priority_queue<int,vector<int>,greater<int> >PQ;structnode{intx, y;};structcmp{BOOL operator() (Node A,node b) {if(a.x==b.x)returnA.y>b.y; returnA.x>b.x; }};BOOLcmpintAintb) { returnA>b;}intN;DoubleA[MAXN];DoubleDP[MAXN];intMain () {#ifndef Online_judge freopen ("In.txt","R", stdin); #endif //freopen ("OUT.txt", "w", stdout); intT; CIN>>u; for(intt=1; t<=t;t++) {cin>>N; for(intI=1; i<=n;i++) scanf ("%LF",&A[i]); CLE (DP); Doubleans=0; dp[1]=1; for(intI=1; i<=n;i++){ for(intJ=max (1, I-6); j<i;j++){ intK=min (N-j,6); Dp[i]+=dp[j]/(k*1.0); } ans+=dp[i]*A[i]; } printf ("Case %d:%.10f\n", T,ans); } return 0;}
Lightoj 1030-discovering Gold