这是一个dp流
dp[i] = dp[i-1] + dp[i-2]*(i-1);
#include <cstdio>
#include <iostream>
#define M 1000010//注意大小
#define N 1000000007
long long L[M];
int main()
{
int n,m;
scanf("%d",&n);
L[1] = 1;
L[2] = 2;
L[3] = 4;
for(int i = 4; i < 1000005;i++)
{
L[i] = (L[i-1]%N + L[i-2] * (i-1)%N)%N;//转移方程,分两类:1、传自己 2、传给别人
}
for(int i = 1; i <= n; i++)
{
scanf("%d",&m);
printf("Case #%d:\n%I64d\n",i,L[m]);
}
return 0;
}