Nyoj-366-D small L (for full Arrangement), nyoj-366-d for full Arrangement
D small L time limit: 4000 MS | memory limit: 65535 KB difficulty: 2
-
Description
-
One day, TC went to the ACM's Xiao L to play with the Three Kingdoms, but this would be a little busy. I don't want to play with Kuang, but I'm afraid of being angry, at this time, Xiao L gave me a question to solve (Xiao L is very D), there is a number of n (0 <n <10), write a full arrangement of 1 to n, at this moment, I am a little confused. Can you help me solve the problem intelligently?
-
Input
-
Enter N (0 <N <10) in the first row, indicating that N groups of test data exist. The next N rows Input Multiple groups of input data, each group of input data is an integer x (0 <x <10)
-
Output
-
Output all combinations in a specific order.
Specific order: Values in each combination are arranged in ascending order, and the combinations are arranged in lexicographically.
-
Sample Input
-
223
-
Sample output
-
1221123132213231312321
-
Source
-
Original
-
Uploaded
-
Kapop
-
1/* 2 * http://acm.nyist.edu.cn/JudgeOnline/problem.php? Pid = 366 3 * by jtahstu on 4 * knowledge point: sort the generator in the lexicographically next order next_permutation () 5 * sort by prev_permutation () in the lexicographically previous order () 6 */7 8 # include <iostream> 9 # include <algorithm> 10 # include <string> 11 using namespace std; 12 13 int main () {14 int n; 15 cin> n; 16 while (n --) 17 {18 int m; 19 string s; 20 cin> m; 21 for (int I = 1; I <= m; I ++) 22 s + = I + '0'; 23 cout <s <endl; 24 while (next_permutation (s. begin (), s. end () 25 cout <s <endl; 26} 27 return 0; 28}
3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 int a[]={1,2,3,4,5,6,7,8,9}; 7 int main() 8 { 9 int n,r;10 cin>>r;11 while(r--)12 {13 cin>>n;14 do15 {16 for(int i=0;i<n;i++)17 cout<<a[i];18 cout<<endl;19 }while(next_permutation(a,a+n));20 }21 return 0;22 }