Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4652
I threw a dice with M faces, and asked me to roll out n identical faces in a row and expect n different faces in a row.
If DP [I] is set, the expectation of I identical/different faces has been thrown, and the final state DP [N] = 0 can be determined,
For N consecutive identical faces
DP [I] = 1/M * DP [I + 1] + (m-1)/m * DP [1] + 1
Then list the sub-DP [I + 1] = 1/M * DP [I + 2] + (m-1)/m * DP [1] + 1
The two formula subtract DP [I + 1]-DP [I] = 1/M * (DP [I + 2]-d [I + 1]), we can find the difference between any two consecutive numbers into an proportional sequence, and we can find the DP [0].
For n different faces
DP [I] = m-1)/m * DP [I + 1] + 1/M * (DP [1] + dp [2] +... + dp [I])
Then list the sub-DP [I + 1] = m-1) /M * DP [I + 2] + 1/M * (DP [1] + dp [2] + .... + dp [I + 1])
Two-phase subtraction DP [I + 1]-DP [I] = (m-i-1)/m * (DP [I + 1]-DP [I + 2]), finally, you can obtain DP [0] for each consecutive subtraction.
# Include <stdio. h> # include <iostream> # include <map> # include <set> # include <list> # include <stack> # include <vector> # include <math. h> # include <string. h> # include <queue> # include <string> # include <stdlib. h> # include <algorithm> // # define ll _ int64 # define ll long # define EPS 1e-8 # define PI ACOs (-1.0) using namespace STD; const int INF = 0x3f3f3f; const int maxn = 100010; int main () {int test; int order, m, N; while (~ Scanf ("% d", & Test) {for (INT I = 1; I <= test; I ++) {scanf ("% d ", & Order, & M, & N); double ans = 1; if (Order = 0) {Double P = m * 1.0, TMP = m * 1.0; for (INT I = 1; I <= n-1; I ++) {ans + = TMP; TMP * = P;} else {double TMP = 1.0; for (INT I = 1; I <= n-1; I ++) {TMP * = m * 1.0/(m-I); ans + = TMP ;}} printf ("%. 9lf \ n ", ANS) ;}} return 0 ;}
HDU 4652 dice (expected)