This question makes the output miserable. The idea of this question is to look at the situation of the n-person. If the n-person takes his previous (n-1) personal things, and the n-person's things, then this event would inevitably happen to f (n-2), and in another case the items of the two were not exchanged, then the rest continued to do it, f (n-1 ). The overall likelihood of occurrence is (n-1) * (f (n-1) + f (n-2). Note that the output % must be connected to two %.
[Cpp]
<SPAN style = "FONT-SIZE: 18px"> # include <iostream>
# Include <stdio. h>
Using namespace std;
_ Int64 a [21] [2];
Int main ()
{
Int I, C, n;
A [2] [1] = 1;
A [2] [0] = 2;
A [3] [1] = 2;
A [3] [0] = 6;
For (I = 4; I <= 20; I ++)
{
A [I] [1] = (I-1) * (a [I-1] [1] + a [I-2] [1]);
A [I] [0] = a [I-1] [0] * I;
}
Cin> C;
While (C! = 0)
{
Cin> n;
Printf ("%. 2f % \ n", a [n] [1] * 100.0/a [n] [0]);
C = C-1;
}
Return 0;
}
</SPAN>
# Include <iostream>
# Include <stdio. h>
Using namespace std;
_ Int64 a [21] [2];
Int main ()
{
Int I, C, n;
A [2] [1] = 1;
A [2] [0] = 2;
A [3] [1] = 2;
A [3] [0] = 6;
For (I = 4; I <= 20; I ++)
{
A [I] [1] = (I-1) * (a [I-1] [1] + a [I-2] [1]);
A [I] [0] = a [I-1] [0] * I;
}
Cin> C;
While (C! = 0)
{
Cin> n;
Printf ("%. 2f % \ n", a [n] [1] * 100.0/a [n] [0]);
C = C-1;
}
Return 0;
}