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);
}
}

你可能感兴趣的:(HDU)