信封

题目描述 Description

某人写了n封信和n个信封,如果所有的信都装错了信封。求所有的信都装错信封共有多少种不同情况?

输入描述 Input Description

n

输出描述 Output Description

n封信都装错信封的情况的数量

样例输入 Sample Input

3

样例输出 Sample Output

2

 

 1 #include <iostream>
 2 
 3 using namespace std;
 4 
 5 int f(int m)
 6 {
 7     if(m==1)
 8         return 0;
 9     if(m==2)
10         return 1;
11     return (m-1)*(f(m-1)+f(m-2));
12 }
13 
14 int main()
15 {
16     int n;
17     cin>>n;
18     cout<<f(n);
19     return 0;
20 }

 

posted @ 2019-02-13 11:14  zhangjs73  阅读(163)  评论(0编辑  收藏  举报