D的小L
时间限制:
4000 ms | 内存限制:
65535 KB
难度:
2
-
描述
- 一天TC的匡匡找ACM的小L玩三国杀,但是这会小L忙着哩,不想和匡匡玩但又怕匡匡生气,这时小L给匡匡出了个题目想难倒匡匡(小L很D吧 ),有一个数n(0<n<10),写出1到n的全排列,这时匡匡有点囧了 ,,,聪明的你能帮匡匡解围吗?
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int T,i,n;
int a[9]={1,2,3,4,5,6,7,8,9};
cin>>T;
while(T--)
{
cin>>n;
do
{
for(i=0;i<n;++i)
cout<<a[i];
cout<<endl;
}while(next_permutation(a,a+n));
}
return 0;
}
C++/STL中定义的next_permutation和prev_permutation函数则是非常灵活且高效的一种方法,它被广泛的应用于为指定序列生成不同的排列。
按照STL文档的描述,next_permutation函数将按字母表顺序生成给定序列的下一个较大的序列,直到整个序列为减序为止。prev_permutation函数与之相反,是生成给定序列的上一个较小的序列。