前t个组合结果
【前t个组合结果】
文章图片
文章图片
#include
#include
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=======================================