题目链接:http://poj.org/problem?id=1833
Description
Input
Output
Sample Input
3 3 1 2 3 1 3 1 3 2 1 10 2 1 2 3 4 5 6 7 8 9 10
Sample Output
3 1 2 1 2 3 1 2 3 4 5 6 7 9 8 10
代码如下:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
int t;
int a[1024];
scanf("%d",&t);
while(t--)
{
int n, m;
scanf("%d%d",&n,&m);
for(int i = 0; i < n; i++)
{
scanf("%d",&a[i]);
}
for(int i = 0; i < m; i++)
{
next_permutation(a,a+n);
}
printf("%d",a[0]);
for(int i = 1; i < n; i++)
{
printf(" %d",a[i]);
}
printf("\n");
}
return 0;
}
原文:http://blog.csdn.net/u012860063/article/details/43115129