HDU 4535 吉哥系列故事——礼尚往来( 错排水题 )


链接:传送门
思路:错排模板题,水题是非常浪费时间的。


/*************************************************************************
    > File Name: hdu4535.cpp
    > Author:    WArobot 
    > Blog:      http://www.cnblogs.com/WArobot/ 
    > Created Time: 2017年04月28日 星期五 15时30分45秒
 ************************************************************************/

#include<bits/stdc++.h>
using namespace std;


#define ll  long long
#define mod 1000000007
int n , t;
ll  d[101];

void init(){
    d[1] = 0;   d[2] = 1;
    for(int i=3;i<=100;i++){
		d[i] = (i-1)*(d[i-1] + d[i-2]);
		d[i] %= mod; 
	}
}
int main(){
    init();
    scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		printf("%lld
",d[n]);
	}
    return 0;
}
原文地址:https://www.cnblogs.com/WArobot/p/6782136.html