[HDU 1465] One of the series is not easy

We often feeling, to do one thing really is not easy, indeed, the failure easier than success! 
Success of the "one" thing yet it is not easy, if you want to always be successful and always never fail, it is more difficult, as always, like to spend money to make money easier than the truth. 
Having said that, I still have to tell you, to fail to a certain extent it is not easy. For example, when I was in high school, there is a magical girl, the English exam, even the 40 multiple-choice all wrong! We all learned probability theory, the probability of such a situation should arise know, so far I think this is a wonderful thing. If you apply a classic comment, we can summarize: a people a wrong choice is not difficult, the difficulty is all wrong, a wrong. 

Unfortunately, such a small probability event took place, and all around us: 
the way it is --HDU have a network name called the male students in 8006, to make countless friends, the student playing the romance recently, while giving n number of users each person wrote a letter, which are nothing, worse, that he should put all the letters are installed wrong envelopes! Attention, all is installed wrong yo! 

The question now is: Please help 8006 poor students to calculate, how many the wrong way on a possible total of it?

Input plurality of test input data comprising a plurality of instances, one row for each test case, each line contains a positive integer n (1 <n <= 20), n represents the number of users 8006. Output For each line of input requested output number of possible wrong way, the output of each instance of the occupation line. Sample Input

2
3

Sample Output

1
2

 

 

Solution: still small cute QAQ combination arrangement

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
typedef long long ll;
using namespace std;
int f[22],n;
ll fun(int n){
    if(n==1)return 0;
    if(n==2)return 1;
    return (n-1)*(fun(n-1)+fun(n-2));
}
int main(){
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    //f[1]=0; f[2]=1; f[3]=2;
    //for(int i=4;i<=20;i++)
        //f[i]=(i-1)*(f[i-1]+f[i-2]);
    while(scanf("%d",&n)!=EOF) 
          printf("%lld\n",fun(n));
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/wuhu-JJJ/p/11329119.html