1294 full arrangement
time limit: 1 sspace limit: 128000 KBtitle level: Golden GoldTitle Description
Description
Given an n, please output all the full permutations of n
Enter a description
Input Description
Read in only one integer n (1<=n<=10)
Output description
Output Description
A total of n! rows, each row n a number separated by a space, representing a full array of n. and output in a fully ordered dictionary sequence.
Sample input
Sample Input
3
Sample output
Sample Output
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
Data range and Tips
Data Size & Hint
//Remember to change all of the following cout to printf.//Otherwise, it'll be t.//I was so lazy, I didn't change it.#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)Const intmaxn= -;intA[MAXN];intB[MAXN];intN;voidinit () {cin>>O; return;}intput () {intfirst=1; for(intI=1; i<=n;i++) { if(first) {printf ("%d", A[i]); First=0; } Elsecout<<" "<<A[i]; } cout<<Endl;}voidWorkintt) { if(t>N) {put (); return; } for(intI=1; i<=n;i++) { if(!B[i]) {B[i]=1; A[t]=i; Work (T+1); B[i]=0; } }}intMain () {//Sspeed;init (); Work (1); return 0;}
Wikioi 1294 full-lined Dfs