Iterative Deepen search ...
Main.cpp//UVA 331-mapping the Swaps////Created by XD on 15/8/8. Copyright (c) 2015 XD.
All rights reserved. #include <iostream> #include <string> #include <queue> #include <stack> #include <stdio.h&
Gt #include <stdlib.h> #include <math.h> #include <vector> #include <string.h> #include <string
> #include <algorithm> #include <set> #include <map> #include <cstdio> using namespace std;
int maxd;
int num;
int n;
int casenum;
int solved;
int a[6];
void Myswap (int *a, int *b) {int temp = *a;
*a = *b;
*b = temp;
void Dfs (int d) {if (d = = Maxd) {for (int i = 0; I <n-1; i++) {if (a[i) > A[i+1]) {
return;
}} num++;
return;
for (int i = 0;i < n-1; i++) {Myswap (&a[i], &a[i+1]);
DFS (D+1);
Myswap (&a[i], &a[i+1]);
} void Solve () {int flag = 1;
for (int i = 0; I <n-1; i++) {if (A[i] > a[i+1]) {flag = 0;
break;
} if (flag) {printf ("There are 0 swap maps for input data set%d.\n", ++casenum);
return;
for (Maxd =1; maxd++) {num = 0;
DFS (0);
if (num > 0) {printf ("There are%d swap maps for input data set%d.\n", Num, ++casenum);
return; int main (int argc, const char * argv[]) {while (scanf ("%d", &n) ==1 && n!= 0) {for (int i =0; i < n; i++)
{scanf ("%d", &a[i]);
} solve ();
return 0;
}