There are n cups, and the ball starts at s position. m times for ball change operations, and K times for the ball. The person who looks at the Ball guesses the final position of the Ball Based on the K times he sees, the most likely output location.
DP [m] [k] [s] indicates the frequency of s when K balls are finally seen in the previous m operations.
# Include <cstdio> # include <cstring> int n, m, K, S, X [55], Y [55]; long long DP [55] [55] [55]; int main () {int I, j, L, t; scanf ("% d", & T ); while (t --) {scanf ("% d", & N, & M, & K, & S); for (I = 1; I <= m; I ++) scanf ("% d", & X [I], & Y [I]); memset (DP, 0, sizeof DP); DP [1] [0] [s] = 1; // The initial state is the position of the ball itself for (I = 1; I <= m; I ++) for (j = 0; j <= K; j ++) for (L = 1; L <= N; l ++) {If (DP [I] [J] [l]) {DP [I + 1] [J] [l] + = DP [I] [J] [l]; // I didn't see this time. // I saw this time if (L = x [I]) DP [I + 1] [J + 1] [Y [I] + = DP [I] [J] [l]; else if (L = Y [I]) DP [I + 1] [J + 1] [x [I] + = DP [I] [J] [l]; else DP [I + 1] [J + 1] [l] + = DP [I] [J] [l]; // here we also need J + 1, that is, we can see this exchange, but there is no impact} int ans = 1; for (I = 2; I <= N; I ++) if (DP [M + 1] [k] [ANS] <DP [M + 1] [k] [I]) ans = I; printf ("% d \ n", ANS);} return 0 ;}
Zoj3605 find the marble --- probability DP