前t个组合结果


#include <iostream>
#include <cstdio>
using namespace std;
int X[31], used[31];
int n, r, t, count;
void output()
{
	for (int i = 1; i <= r; ++i)//输出r个
	{
		printf(" %d", X[i]);
	}
	putchar('\n');
}

int pruning(int i)
{
	if (used[i])	return 0;
	return 1;
}

void f(int k, int i)
{
	if (t == count)	return ;
	if (k - 1 == r)//只组合r个
	{
		++count;
		output();
	}
	else
	{
		for (;i >= 1; --i)
		{
			if (pruning(i))
			{
				X[k] = i;
				used[i] = 1;
				f(k + 1, i - 1);
				used[i] = 0;
			}
		}
	}
}

int main()
{
	scanf("%d %d %d", &n, &r, &t);
	f(1, n);
	return 0;
}
========================================Talk is cheap, show me the code=======================================
posted @ 2018-02-27 14:43  绿叶萌飞  阅读(194)  评论(0编辑  收藏  举报