Transmission Door
To 0-n so many lattice, initial in 0, and then throw the dice, throw to a few steps, some of which are connected, such as 2,5 connected, then to 2 can fly directly to 5. Ask for the desired number of steps at N.
The first must be backwards, dp[n] = 0. Then if x, Y (x<y) is connected, then dp[x] = Dp[y]. The transfer equation is very well written. See Code for details
1#include <bits/stdc++.h>2 using namespacestd;3 #defineMem (a) memset (a, 0, sizeof (a))4 Doubledp[100005];5 intNum, f[100005], vis[100005];6 intMain ()7 {8 intN, m, x, y;9 while(cin>>n>>m) {Ten if(n+m==0) One Break; A mem1 (f); - while(m--) { -scanf"%d%d", &x, &y); theF[X] =y; - } - Mem (DP); - mem (VIS); +Dp[n] =0; - for(inti = n1; i>=0; i--) { + if(~F[i]) { ADp[i] =Dp[f[i]]; at}Else { - for(intj =1; j<=6; J + +) { -Dp[i] + = (1+DP[I+J])/6.0; - } - } - } inprintf"%.4f\n", dp[0]); - } to}
1#include <bits/stdc++.h>2 using namespacestd;3 #defineMem (a) memset (a, 0, sizeof (a))4 Doubledp[100005];5 intNum, f[100005], vis[100005];6 intMain ()7 {8 intN, m, x, y;9 while(cin>>n>>m) {Ten if(n+m==0) One Break; A mem1 (f); - while(m--) { -scanf"%d%d", &x, &y); theF[X] =y; - } - Mem (DP); - mem (VIS); +Dp[n] =0; - for(inti = n1; i>=0; i--) { + if(~F[i]) { ADp[i] =Dp[f[i]]; at}Else { - for(intj =1; j<=6; J + +) { -Dp[i] + = (1+DP[I+J])/6.0; - } - } - } inprintf"%.4f\n", dp[0]); - } to}
HDU 4405 aeroplane Chess probability DP