N people are queuing up to try the game. There are four situations at the top of the team. 1. The action fails to be re-connected, the queue remains unchanged, the probability is p1. 2. The server connection fails to be re-connected. The first person is at the end of the team, and the probability is p2. 3. The connection is successful. The first person leaves the team, the probability is p3. 4. The server is collapsed and terminated. The probability is p4. locate a person in the m position. When the server is collapsed, there is a probability that there are fewer than k people in front of him. Problem-solving ideas: we have done similar probability dp before, and there are iterations and Gaussian deyuan to solve the equation. It is not sequential, but we didn't write a blog, so we didn't do it .. Because the number of people changes, the number of people needs to be set to one dimension, and the position of the person is also changing to the second dimension. Dp [I] [j] indicates a total of I people. When this person is at the position of j, the probability of the event to be requested occurs. When j = 1, this person has three options: 1, 2, and 4, dp [I] [1] = p1 * dp [I] [1] + p2 * dp [I] [I] + p4 when 2 = <j <= k, the first person selected from 1, 2, 3, and 4 to make the event happen, dp [I] [j] = p1 * dp [I] [j] + p2 * dp [I] [J-1] + p3 * dp [I-1] [J-1] + p4 when j> k, the first person has one, two, and three options for an event, dp [I] [j] = p1 * dp [I] [j] + p2 * dp [I] [J-1] + p3 * dp [I-1] [J-1], simplified: j = 1 dp [I] [j] = pp2 * dp [I] [I] + pp4 2 = <j <= k dp [I] [j] = pp2 * dp [I] [J-1] + pp3 * dp [I-1] [J-1] + pp4 j> k, dp [I] [j] = pp2 * dp [I] [J-1] + pp3 * dp [I-1] [J-1] dp [1] [1] can be directly obtained. Calculate dp [I] from dp [1] recursively, and then add other unknown numbers to the dp [I] [j] equation for each dp [I, iteratively obtain dp [I] [j]. then, recursively obtain dp [I] [j]. code:
# Include <iostream> # include <cmath> # include <cstdio> # include <cstdlib> # include <string> # include <cstring> # include <algorithm> # include <vector> # include <map> # include <set> # include <stack> # include <list> # include <queue> # define eps 1e-8 # define INF 0x1f1f1f1f # define PI acos (-1.0) # define ll _ int64 # define lson l, m, (rt <1) # define rson m + 1, r, (rt <1) | 1 # pragma comment (linker, "/STACK: 1024000000,1024000000") using namespa Ce std; // freopen ("data. in "," r ", stdin); // freopen (" data. out "," w ", stdout); # define Maxn 2005 double dp [Maxn] [Maxn]; // dp [I] [j] indicates a total of I people, the probability that the person in the j position will have the event double p1, p2, p3, p4, temp [Maxn]; // temp [I] indicates the constant double pp [Maxn] in the previous layer when dp [I] [j] is obtained; // pp [I] indicates pp ^ I, used for iterative query of dp [I] [I]; int n, m, k; int main () {double pp2, pp3, pp4; while (~ Scanf ("% d", & n, & m, & k) {scanf ("% lf", & p1, & p2, & p3, & p4); if (p4 <= eps) // The last step must be * P4. if p4 is small, 0.00000 {puts ("0.00000"); continue;} pp2 = p2/(1-p1); pp3 = p3/(1-p1); pp4 = p4/(1-p1 ); pp [0] = 1.0; for (int I = 1; I <= n; I ++) pp [I] = pp [I-1] * pp2; // used for iteration retention coefficient dp [1] [1] = p4/(1-p1-p2); // according to equation 1, you can quickly find for (int I = 2; I <= n; I ++) {temp [1] = pp4; for (int j = 2; j <= k; j ++) temp [j] = pp3 * dp [I-1] [J-1] + pp4; for (int j = k + 1; j <= I; j ++) temp [j] = pp3 * dp [I-1] [J-1]; // constant double tmp = 0.0 for equation j; // obtain the constant portion of the unknown equation containing only dp [I] [I] for (int j = I; j> = 1; j --) tmp + = temp [j] * pp [I-j]; // bring the preceding equation into the following equation dp [I] [I] = tmp/(1-pp [I]); dp [I] [1] = pp2 * dp [I] [I] + temp [1]; // obtain the value of the unknown following the equation for (int j = 2; j <I; j ++) dp [I] [j] = pp2 * dp [I] [J-1] + temp [j];} printf ("% 0.5f \ n", dp [n] [m]);} return 0 ;}