UVA 331 Mapping The Swaps

Source: Internet
Author: User

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.