Throw a dice with a M face, each face has a number, these numbers are different, for continuous throw to n the same number of the desired number of steps or the number of successive throw to n the number of expected steps
The same:
E[i] Indicates that there are already I consecutive the same, the desired number of steps to reach the target
e[i]=e[i+1]/m+ (1-1/m) e[1] ......... ..... 1
e[i+1]=e[i+2]/m+ (1-1/m) e[1] ......... 2
1-2 e[i]-e[i+1]= (e[i+1]+e[i+2])/m
Set S[i]=e[i]-e[i+1],
Then S[0]=e[0]-e[1]=1,s[i+1]=m*s[i],ans=sigma (S[i]) (0<=i<n)
Different:
E[i] Indicates that I have a continuous difference, the desired number of steps to reach the target
E[i]=simga (E[j])/m+ ((m-i)/m) e[i+1], (1<=j<=i) ....... 1
E[i+1]=sigma (E[j])/m+ ((m-i-1)/m) e[i+2], (1<=j<=i+1) .... 2
1-2 e[i]-e[i+1]= (m-i-1)/m* (e[i+1]-e[i+2])
Set S[i]=e[i]-e[i+1],
Then s[0]=e[0]-e[1]=1,s[i+1]=m/(m-i-1) S[i],ans=sigma (S[i]) (0<=i<n)
1#include <bits/stdc++.h>2 using namespacestd;3 #defineMAXN 10000054 intT,op,n;5 DoubleM,S[MAXN];6 voidsolve0 () {7s[0]=1;8 Doubleans=s[0];9 for(intI=0; i<n-1; i++)Tens[i+1]=s[i]*m,ans+=s[i+1]; Oneprintf"%.9lf\n", ans); A } - voidsolve1 () { -s[0]=1; the Doubleans=s[0]; - for(intI=0; i<n-1; i++) -s[i+1]=m/(m-i-1) *s[i],ans+=s[i+1]; -printf"%.9lf\n", ans); + } - intMain () { +scanf"%d",&T); A while(t--){ atscanf"%d%lf%d",&op,&m,&n); - if(op==0) solve0 (); - Elsesolve1 (); - } - return 0; -}
View Code
[HDU4652] Dice