One of the series is not easy (hdu1465) Error row + recurrence, one of the series is hdu1465

Source: Internet
Author: User

One of the series is not easy (hdu1465) Error row + recurrence, one of the series is hdu1465
One of the hard Series

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 16646 Accepted Submission (s): 6935


Problem Description we often feel that it is really not easy to do one thing well. Indeed, failure is much easier than success!
It is not easy to do the "one thing" thing well. If you want to succeed forever and never fail, it is even harder, just as spending money is always easier than making money.
Even so, 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 who did all the 40 single-choice questions wrong during the English test! Everyone has learned probability theory and should know the probability of such a situation. So far, I think this is a magic thing. If we use a classic comment, we can conclude that it is not difficult for a person to make a wrong choice question. What is difficult is to make all the mistakes wrong or wrong.

Unfortunately, this kind of small probability event happened again, and it was around us:
This is the case -- HDU has a male student named 8006, who has made countless friends. Recently, this student played a romantic game and wrote a letter to each of the n netizens. This is nothing, the worst thing is, he put all the messages in the wrong envelope! Note: It's all wrong!

The question is: How many possible error methods are there for the poor 8006 students?
The Input data contains multiple test instances. Each test instance occupies one row and each row contains a positive integer of n (1 <n <= 20). n indicates the number of netizens of 8006.
Output: for each line of input, please Output the number of possible error methods. The Output of each instance occupies one line.
Sample Input
23
 
Sample Output
12
Is an error row, the formula is f [n] = (n-1) * (f [n-1] + f [N-2]); reasoning process can be clicked: Error row reprint please indicate the source: search for my child questions link: http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 1465
#include<stdio.h>#define LL long longLL f[25];void init(){    f[0]=0;    f[1]=0;    f[2]=1;    for(int i=3;i<=20;i++)    {        f[i]=(i-1)*(f[i-1]+f[i-2]);    }}int main(){    int n;    init();    while(scanf("%d",&n)!=EOF)    {        printf("%lld\n",f[n]);    }    return 0;}

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.