#include <cstdio> #include <algorithm> #include <cstring> #include <iostream> using namespace std; int partner[100]; int N; int total; void dfs() { int i; for(i=1; i<=N; i++) if(partner[i]==0) break; if(i > N) { // for(int i=1; i<=N; i++) // printf("%d - %d\n", i, partner[i]); // printf("\n"); total++; return ; } for(int j=i+1; j<=N; j++) { if(partner[j]==0) { partner[i] = j; partner[j] = i; dfs(); partner[i] = 0; partner[j] = 0; } } } int main() { scanf("%d", &N); memset(partner, 0, sizeof(partner)); total = 0; dfs(); cout<<total<<endl; return 0; }
时间: 2024-10-13 08:19:27