hdu 2068 错排

这几天做了好几道错排题目,这题就直接在hdu2069的代码上改了,直接过了

/*
* hdu2068/linux.c
* Created on: 2011-7-31
* Author : ben
*/
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
#include
<math.h>

void work();
int main() {
#ifndef ONLINE_JUDGE
freopen(
"data.in", "r", stdin);
#endif
work();
return 0;
}

long long ans[26][26];

void init() {
int i, j, k;
memset(ans,
0, sizeof(ans));
ans[
2][2] = 1;
ans[
3][3] = 2;
ans[
3][2] = 3;
for (i = 4; i <= 25; i++) {
ans[i][i]
= (i - 1) * (ans[i - 1][i - 1] + ans[i - 2][i - 2]);
for (j = i - 1; j > 2; j--) {
ans[i][j]
= ans[i - 1][j];
ans[i][j]
+= ans[i - 1][j - 1] * (j - 1);
ans[i][j]
+= ans[i - 1][j - 2] * (i - j + 1);
}
ans[i][
2] = ans[i - 1][2] + i - 1;
}
}
void work() {
int T, temp;
long long res;
init();
while (scanf("%d", &T) == 1 && T > 0) {
res
= 1;
for(temp = T / 2; temp > 0; temp--) {
res
+= ans[T][temp];
}
printf(
"%lld\n", res);
}
}

转载于:https://www.cnblogs.com/moonbay/archive/2011/07/31/2122674.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值