HDU 1465 not easy to line up the wrong line

Source: Internet
Author: User

Time limit:1000MS Memory Limit:32768KB 64bit IO Format:%i64d &%i64 U

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

2 3

Sample Output

1 2

Program Analysis: It is also a topic that is easy to AC as long as there is a formula.

Wrong-row formula: F (N) = (n-1) * (f (n-1) +f (n-2))

The following recursive method is used to derive the formula of the wrong line:

When n numbered elements are placed in n numbered positions, the number of methods that do not correspond to the number of the element and the position number is expressed in M (n), then M (n-1) indicates that the n-1 number element is placed in the n-1 number position, the number of methods that do not correspond, and other analogies.  

The first step is to put the nth element in a position, such as position k, altogether there are n-1 methods

The second step is to put the element with the number k, and there are two cases.

1, put it to position N, then, for the remaining n-2 elements, there is M (n-2) method;

2, do not put it to position N, at this time, for this n-1 element, there is M (n-1) method;

The Comprehensive
M (n) = (n-1) [M (n-2) +m (n-1)]
Program code:
#include <stdio.h>intMain () {_int64 a[ -]={0,1,2}; intN,i;  for(i=3;i< -; i++) A[i]=i* (a[i-1]+a[i-2]);  while(SCANF ("%d", &n)! =EOF) printf ("%i64d\n", a[n-1]); return 0;}

HDU 1465 not easy to line up the wrong line

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.