At first, my idea was to fix the half. The other half was added to the combination formula Cn1 + cn2 + cn3 + CN4 +... + CNI. Finally, we could subtract them from the full arrangement.
Finally, we found that the train of thought was totally wrong. We had to use the wrong sorting formula for calculation.
That is, CNM * A [n-M]; select m from N people, and use the wrong rank formula to calculate the number of N-m people that are not in the corresponding position.
The result is displayed based on the principle of step-by-step counting.
# include
double zuhe (int n, int m)
{< br> double S = 1, I;
for (I = 0; I S = S * (N-I)/(I + 1);
return S;
}< br> int main ()
{< br> int n, m, I;
double s [26], sum;
S [1] = 0; s [2] = 1;
for (I = 3; I <26; I ++)
S [I] = (I-1) * (s [I-1] + s [I-2]);
while (scanf ("% d", & N) = 1 & n! = 0)
{< br> sum = 0;
If (N % 2 = 0)
M = n/2;
else
M = (n + 1)/2;
for (I = m; I sum = sum + zuhe (n, I) * s [n-I];
printf ("%. LF \ n ", sum + 1);
}< br> return 0;
}