标签:
2 2 3
12 21 123 132 213 231 312 321
1 /* 2 * http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=366 3 * by jtahstu on 2015/2/5 4:00 4 * 知识点: 排列生成器 按字典序的下一个排列 next_permutation() 5 * 按字典序的前一个排列 prev_permutation() 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 do 15 { 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 }
标签:
原文地址:http://www.cnblogs.com/jtahstu/p/4273811.html