Analysis of troubleshooting and troubleshooting
Definition:N ordered elements should have n! . If an arrangement does not place all elements in the original position, it is called an incorrect arrangement. Let's give an n, and find the number of "D" for "1, 2, 3", "...", and give all the error troubleshooting solutions.
Reasoning:
Step 1: place the nth element in a single position, such as position k. There are n-1 methods in total;
Step 2: place the element number k in two cases: (1) place it in position n. Then, for the remaining n-1 elements, since the k element to the position n, the remaining N-2 element has D (n-2) method; (2) the k element does not put it to the position n, then, for this n-1 element, there are D (n-1) methods; so: D (n) = (n-1) * [D (n-1) + D (n-2)]; D (1) = 0, D (2) = 1e. gOh, my God! Time Limit: 1000 MS | memory limit: 65535 KB difficulty: 2
-
Description
-
In order to happy everyone, organizer HRW held an open up partythere have specific ments for this activity is this:
First of all, all persons in the party will have to write a note to his name into the box; Then, after all the note added is completed, each taking a note from the box; finally, if made note of your name, then "Congratulations, won the party! "
Oh, my God!
Now to the question, you can calculate the probability of this happening? Don't count? Don't you want said by others as a DouBi ?! AC it!
-
Input
-
Input file contains several test cases. each test case consists of a integer numbers n on a line (one ≤ n ≤ ten ). the last test case is followed by a line that contains one zeroes. this line must not be processed.
-
Output
-
Print the probability
See the following example.
-
Sample Input
-
230
-
Sample output
-
Case [1]: 50.00%.Case [2]: 33.33%.
-
Prompt
-
You need to use the wrong rank formula to calculate the probability that everyone draws their own names.
-
Source
-
Original
-
Uploaded
-
ACM _ he rongwei
First of all, all the participants will put a note with their own name into the lottery box;
Then, after all the notes are added, each person takes a note from the box;
Finally, if you write your own name on the obtained note, "Congratulations, you have won the prize !"
Calculate the probability of this situation?
Train of Thought: in fact, the use of the wrong rank formula p = D (n)/n !;
#include<stdio.h>int main(){ double a[55]; double b[55]; a[0]=1; for(int i=1;i<=22;i++) a[i]=a[i-1]*i; b[1]=0; b[2]=1; b[3]=2; for(int i=4;i<=22;i++) b[i]=(i-1)*(b[i-1]+b[i-2]); int n,d=1; while(~scanf("%d",&n),n) { printf("Case [%d]: ",d++); if(n==1) printf("100.00%%.\n"); else { printf("%.2lf%%.\n",100*b[n]/a[n]); } }}