1 条题解
-
0
C++ :
#include <iostream> #include <iomanip> #include <string> #include <string.h> #include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> using namespace std; int n,a[21],count,s[12]; bool f[21]; void jh(int i,int j) { int temp; temp=a[i]; a[i]=a[j]; a[j]=temp; } void cz(int i) { int j,k,flat; if (i>n)//&& { // flat=0; count++; for (k=1;k<n;k++) printf("%5d",a[k]); // printf("\n"); printf("%5d\n",a[k]); // for (k=1;k<=n;k++) // if (a[k]!=n-k+1) // flat=1; // if (flat) // printf("",a[k]); return ; } for (j=1;j<=n;j++) { if (f[j]) continue ; a[i]=j; f[j]=1; cz(i+1); f[j]=0; } } int main() { int i,j; while (scanf("%d",&n)!=EOF) { count=0; memset(f,0,sizeof(bool)); cz(1); // printf("%d\n",count); } return 0; }
- 1
信息
- ID
- 1194
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者