链接:传送门
题意:
思路:next_permutation(),水,但是要注意一点的是如果是最后一个排列next_permutation会返回第一个排列并结束,所以如果到了最后一个排列还不是第k个就处理一下即可

/*************************************************************************
    > File Name: 31.cpp
    > Author:    WArobot 
    > Blog:      http://www.cnblogs.com/WArobot/ 
    > Created Time: 2017年04月19日 星期三 22时15分06秒
 ************************************************************************/

#include<cstdio>
#include<algorithm>
using namespace std;

int t,n,k;
int s[1034];
int main(){
	scanf("%d",&t);
	while(t--){
		scanf("%d%d",&n,&k);
		for(int i=0;i<n;i++)	scanf("%d",s+i);
		int cnt = 0 , i;
		do{
			cnt++;
			for(i=0;i<n;i++)
				if(s[i]!=n-i)	break;
			if(i==n){
				cnt++;
				for(int i=0;i<n;i++)	s[i]=i+1;
			}
			if(cnt == k+1)	break;
		}while(next_permutation(s,s+n));
		for(int i=0;i<n;i++)	printf("%d%c",s[i],i==n-1?'\n':' ');
	}
	return 0;
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2022-12-23
  • 2022-02-09
  • 2021-10-22
  • 2022-01-12
猜你喜欢
  • 2021-09-12
  • 2022-03-03
  • 2021-09-22
  • 2021-09-27
  • 2022-01-02
  • 2022-03-09
相关资源
相似解决方案