Cod sursa(job #731427)
| Utilizator | Data | 8 aprilie 2012 01:02:00 | |
|---|---|---|---|
| Problema | Combinari | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
using namespace std;
#include<cstdio>
#define MAX 25
int n,k,v[MAX];
void afisare(int v[], int n)
{
for(int i=1;i<=n;i++)
printf("%d ",v[i]);
printf("\n");
}
void back(int w, int step)
{
if(w<=n-k+step)
if(step<k)
{
v[step]=w;
for(int i=1;i<=n-k+step+1-w;i++)
back(w+i,step+1);
}
else
{
v[step]=w;
afisare(v,step);
}
}
int main()
{
freopen("combinari.in","r",stdin);
freopen("combinari.out","w",stdout);
scanf("%d %d",&n,&k);
back(0,0);
return 0;
}
