POJ1833 排列

题意:

中文题

要点:

注意这里讨论的是1~n,所以就算你输入98765,输出还是12345


15291544 Seasonal 1833 Accepted 172K 454MS C++ 512B 2016-03-20 09:42:42
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;

int main()
{
	int t,m,k;
	int a[1500];
	scanf("%d", &t);
	while (t--)
	{
		scanf("%d%d", &m, &k);
		for (int i = 0; i < m; i++)
			scanf("%d", &a[i]);
		int count = 0;
		while (1)
		{
			if (count == k) break;
			if (!next_permutation(a, a + m))
				for (int i = 0; i < m; i++)
					a[i] = i + 1;<span style="white-space:pre">	</span>//改为第一个排列
			count++;
		}
		for (int i = 0; i < m - 1; i++)
			printf("%d ", a[i]);
		printf("%d\n", a[m - 1]);
	}
	return 0;
}



posted @ 2016-03-20 09:46  seasonal  阅读(78)  评论(0编辑  收藏  举报