There are a total of n rounds of walk, each time can be left to the right or do not move. Expect to reach the rightmost end
# Include <cstdio> # include <algorithm> # include <cstring> # include <iostream> using namespace std; double l, r, m; int n; double dp [103] [222] [222]; void solve () {m = 1-r-l; dp [0] [100] [100] = 1; for (int I = 1; I <= n; I ++) {for (int j = 100-i; j <= 100 + I; j ++) {for (int k = max (100, j); k <= 100 + I; k ++) // k must exist> = j> = 100 {if (j = k) dp [I] [j] [k] = dp [I-1] [j] [k] * m + dp [I-1] [J-1] [k-1]/* First to k points */* r + dp [I-1] [J-1] [k]/* has been to k point */* r; else dp [I] [j] [k] = dp [I-1] [j] [k] * m + dp [I-1] [J-1] [k] * r + dp [i-1] [j + 1] [k] * l; // The k point is previously reached. }}} int main () {int cas, id; scanf ("% d", & cas); while (cas --) {scanf ("% d % lf", & id, & n, & l, & r); solve (); double ans = 0; for (int I = 100; I <= 100 + n; I ++) for (int j = 100-n; j <= 100 + n; j ++) ans + = dp [n] [j] [I] * (i-100); printf ("% d %. 4lf \ n ", id, ans);} return 0 ;}