您的位置:首页 > 其它

hdu 4535 吉哥系列故事——礼尚往来

2014-10-14 10:20 218 查看
http://acm.hdu.edu.cn/showproblem.php?pid=4535

错排公式:a[i]=(i-1)*(a[i-2]+a[i-1]);

#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
#define maxn 10000
using namespace std;
const ll mod=1000000000+7;

int t;
int n;
ll a[maxn];

int main()
{
scanf("%d",&t);
a[1]=0; a[2]=1;
for(int i=3; i<=100; i++)
{
a[i]=((i-1)*(a[i-2]+a[i-1]))%mod;
}
while(t--)
{
scanf("%d",&n);
printf("%lld\n",a
);
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: