Original question;
Description
We often feel that to do a good thing is really not easy, indeed, failure is much easier than success!
Doing "One" thing is not easy, if you want to always succeed and always never fail, it is even more difficult, like spending money is always easier than the truth.
That said, I still want to tell you that it is not easy to fail to a certain extent. For example, when I was in high school, there was a magical girl, in the English exam, unexpectedly put 40 single-choice questions all wrong! Everyone has learned probability theory, should know the probability of this situation, so far I think this is a magical thing. If we apply a classic comment, we can conclude that it is not difficult for a person to do a wrong choice, and it is difficult to do all wrong.
Unfortunately, this small probability event has happened again, and it's around us:
The thing is this ――hdu has a network name called 8006 Male classmates, make countless friends, recently the classmate played a romantic, at the same time to n a Netizen each wrote a letter, this is nothing, it is, he unexpectedly put all the letters are loaded the wrong envelope! Watch out, it's all loaded wrong yo!
Now the question is: please help the poor 8006 students to calculate, altogether how many kinds of possible wrong way?
Input
The input data contains more than one test instance, one row per test instance, each row containing a positive integer n (1<n<=20), and N represents the number of 8006 netizens.
Output
For each line of input, output the number of possible error modes, and the output of each instance consumes one row.
Sample Input
23
Sample Output
12 Analysis: The typical problem of wrong row, with the idea of the wrong line:
1, when n=1 and 2 o'clock, the easy solution ~, assuming F (N-1) and F (N-2) has been obtained, focusing on the following conditions:
2, when there are N letters, the front N-1 letter can have N-1 or N-2 seal the wrong outfit
3, the former, for each of the wrong outfit, from the N-1 letter can be arbitrarily taken a letter and the nth seal, so =f (N-1) * (N-1)
4, the latter simple, can only be not installed the wrong and the first N sealed Exchange envelopes, the seal is not the wrong one can be in front of the N-1 seal any of them, it is equal to F (N-2) * (N-1)
The code is very short, the key is the wrong line of thought
Code:
#include <stdio.h>#include<string.h>#include<iostream>using namespacestd;intMain () {intN, I; __int64 a[ -]; a[2] =1; a[3] =2; for(i =4; I <= +; i++) A[i]= (I-1) * (A[i-1] + a[i-2]); while(SCANF ("%d", &n)! =EOF) printf ("%lld\n", A[n]); return 0;}
hdu:1465 not easy Series One of the problem-solving experience