标签:
1 /*
2 找规律:题目真心读不懂,排列组合的题目
3 */
4 #include <cstdio>
5 #include <iostream>
6 #include <algorithm>
7 #include <cstring>
8 using namespace std;
9
10 typedef long long ll;
11
12 const int MAXN = 1e6 + 10;
13 const int INF = 0x3f3f3f3f;
14 const int MOD = 1e9 + 7;
15 ll dp[MAXN];
16
17 void solve(void)
18 {
19 dp[1] = 1; dp[2] = 2;
20 for (int i=3; i<=1e6; ++i)
21 {
22 dp[i] = (dp[i-1] + (i - 1) * dp[i-2]) % MOD;
23 }
24 }
25
26 int main(void) //2015百度之星资格赛 1001 大搬家
27 {
28 solve ();
29 int t, cas = 0;
30 scanf ("%d", &t);
31 while (t--)
32 {
33 int n; scanf ("%d", &n);
34 printf ("Case #%d:\n", ++cas);
35 printf ("%I64d\n", dp[n]);
36 }
37
38 return 0;
39 }
40
41
42 /*
43 2
44 1
45 3
46 */
标签:
原文地址:http://www.cnblogs.com/Running-Time/p/4544621.html