#include <iostream>
#include <stdio.h>
using namespace std;
const int MAX = 1000;
int a[MAX];
bool b[MAX];
void f1(int n, int k, int indexn, int indexk){
int i, j;
for(i = indexn; i <= n - k + indexk; i++){
if(!b[i]) {
b[i] = true;
a[indexk] = i;
if(indexk == k) {
for(j = 1; j <= k; j++) {
printf("%d ", a[j]);
}
printf("\n");
} else {
f1(n, k, indexn + 1, indexk + 1);
}
b[i] = false;
}
}
}
void f(int n, int k) {
int i;
for(i = 1; i <= n; ++i) {
a[i] = i;
b[i] = false;
}
f1(n, k, 1, 1);
}
int main()
{
int n,k;
while(scanf("%d %d",&n,&k) == 2)
{
f(n,k);
}
return 0;
}
No comments:
Post a Comment