[1706] Luo valley full array problem

Title Description

Any number of allowed sequence of all distinct arranged to output a natural number n, i.e., n whole arrangement requires the generated duplicate numbers appear.

Input and output formats

Input formats:

 

n(1≤n≤9)

 

Output formats:

 

All numbers are not repeated sequence consisting of a 1 ~ n, a sequence of each row. Each number 5 Reserved often wide.

 

Sample input and output

Input Sample # 1:  Copy
3
Output Sample # 1:  Copy
    1 2 3 
    1 3 2 
    2 1 3 
    2 3 1 
    3 1 2 
    3 2 1 solution to a problem emmm full permutation problem, there are function can be called directly oh

// luogu-judger-enable-o2
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
typedef long long ll;
using namespace std;
int n,a[18];
int main(){
    //freopen("1706.in","r",stdin);
    //freopen("1706.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        { a[i]=i; printf("    %d",i); } 
    while(next_permutation(a+1,a+1+n)){
          printf("\n");
          for(int i=1;i<=n;i++) 
              printf("    %d",a[i]);
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/wuhu-JJJ/p/11224396.html