Ytu 2845: Programming Questions ab-Card game DfsA

Source: Internet
Author: User

2845: Programming Puzzle ab-Card game time Limit: 1 Sec Memory Limit: MB
Submit: Solved: 9
[Submit] [Status] [Web Board] Description

Xiaoming has an interest in the sequence of numbers:
There are many different digital cards, which can be used to arrange a number of sequences, requiring the total number of cards to be calculated, and outputting these sequences in order from small to large.

Input

Enter the number n, which indicates the number of input series, and then enter n different numbers, representing the numbers on n cards (0<= digital <=9,1<=n<=6).

Output

For each group of cards, output all sequences that can consist of these cards in order from small to large, one for each line, and the numbers in the sequence separated by spaces.

Sample Input
31 4 2
Sample Output
61 2 41 4 22 1 42 4 14 1 24 2 1
HINT

Source

Lyh

AC Code:
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio>using namespace Std;int a[12],b[12],c[12],n;void dfs (int step) {    int i;    if (step==n+1) {        for (i=1;i<n;i++) printf ("%d", A[i]);        printf ("%d\n", A[n]);        return;    }    for (i=1;i<=n;++i) {        if (b[i]==0) {            a[step]=c[i];            B[i]=1;            DFS (step+1);            b[i]=0;        }    }    return;} int main () {    while (cin>>n) {        int sum=1, I;        Memset (b,0,sizeof (b));        for (i=1;i<=n;++i) {            cin>>a[i];            C[i]=a[i];            }        for (i=n;i>0;i--) sum*=i;        cout<<sum<< ' \12 ';        Sort (a,a+n+1);        Sort (c,c+n+1);        for (I=1;i<=n;++i) cout<<a[i]<< ";        DFS (1);    }    return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Ytu 2845: Programming Questions ab-card game DfsA

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.