https://www.cnblogs.com/coolwind-sea/archive/2012/04/17/2454313.html
#include <iostream>
#include <algorithm>
#include <iterator>
#include <stdio.h>
using namespace std;
int num[1024];
int main() //408K 516MS
{
int cas,n,k,i;
scanf("%d",&cas);
while(cas--)
{
scanf("%d%d",&n,&k);
for(i=0; i<n; i++)
scanf("%d",&num[i]);
for(i=0; i<k; i++)
next_permutation(num,num+n);
copy(num,num+n-1,ostream_iterator<int>(cout," "));
cout<<num[n-1]<<endl;
}
return 0;
}