The consciousness of this problem is to give you a ring lattice, from 1-n clockwise, just start the robot in 1, then the robot will walk m times, each walk a quota of the deployment, and then ask you the last robot fell in the range of L-r, the time card is tight, pay attention to the way of writing procedures, using brush table method can be, code as follows
#include <cstdio>#include<algorithm>#include<cstring>using namespacestd;Doubledp[2][205];intN, M, L, R;intMain () { while(SCANF ("%d%d%d%d", &n, &m, &l, &r) = =4){ if(N+m+l+r = =0) Break; Memset (DP,0,sizeof(DP)); dp[0][0] =1; for(intI=0; i<m; i++) {memset (dp[(i+1) &1],0,sizeof(dp[0])); intsteps; scanf ("%d", &steps); for(intj=0; j<n; J + +){ if(dp[i&1][J] = =0.0)Continue; dp[(i+1) &1[(J+steps)%n] + =0.5*dp[i&1][j]; dp[(i+1) &1[((J-steps)%n+n)%n] + =0.5*dp[i&1][j]; } } Doubleres =0; for(intj=l-1; j<=r-1; J + +) Res+ = dp[m&1][j]; printf ("%.4f\n", RES); } return 0;}
HDU4576 probability DP