HDU1465 week 6 questions (number of incorrect combinations) and hdu1465 week 6

Source: Internet
Author: User

HDU1465 week 6 questions (number of incorrect combinations) and hdu1465 week 6
L-count, arrangeTime Limit:1000 MSMemory Limit:32768KB64bit IO Format:% I64d & % I64u

Description

People 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 and has made countless friends, recently, this classmate played a romantic game and wrote a letter to each of the n netizens. It was nothing. It was terrible that he had put all the letters in the wrong envelope! Note: It's all wrong!
The question is: How many possible error methods are there for the poor 8006 students?

Input

The input data contains multiple test instances. Each test instance occupies one row. 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, each instance occupies one line of output.

Sample Input

23

Sample Output

12. Question: all possible combinations where all numbers are not in their own positions are required. This is equivalent to a wrong combination, a mathematical problem, and a formula .. D (n) = (n-1) * D (n-1) + (n-1) * D (n-2) = (n-1) (D (n-1) + D (n-2 ))
#include<iostream>using namespace std;long long a[25];int main(){    int n;    while(cin>>n)    {        a[2]=1;        a[3]=2;        for(int i=3;i<=n;i++)        {            a[i]=(i-1)*(a[i-1]+a[i-2]);        }        cout<<a[n]<<endl;    }}

 

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.