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