Pagini recente » Cod sursa (job #409451) | Cod sursa (job #3153941) | Cod sursa (job #2960172) | Cod sursa (job #1478117) | Cod sursa (job #2386657)
#include <bits/stdc++.h>
#define NM 20
using namespace std;
ifstream f("a.in");
ofstream g("a.out");
int k,n,top,st[NM];
void Write()
{ for(int i=1; i<=n; i++) g<<st[i]<<' ';
g<<'\n';
}
bool Valid()
{ for(int i=1; i<top; i++)
if(st[i]==st[top]) return 0;
return 1;
}
void BKT()
{ st[++top]=0;
while(top && k)
{ bool ok=0;
while(!ok && st[top]<n)
{ st[top]++;
ok=Valid();
}
if(!ok) top--;
else
if(top==n)
{ Write();
k--;
}
else st[++top]=0;
}
}
int main()
{ f>>k>>n;
BKT();
return 0;
}