You are on page 1of 1

#include <iostream.

h>
int st[100],n;
void initializare(int i)
{st[i]=0;}
int validare(int k)
{int i;
for(i=1;i<k;i++){
if(st[i]==st[k])
return 0;}
return 1;
}
int solutie (int k)
{return k==n;}
int succesor(int i)
{if(st[i]<n){
st[i]=st[i]+1;;
return 1;}
else return 0;
}
void afisare()
{int i;
for(i=1;i<=n;i++)
cout<<st[i]<<" ";
cout<<endl;
}
void bktr(int i)
{initializare(i);
while (succesor (i)){
if(validare(i))
if(solutie(i))
afisare();
else bktr(i+1);
}
}
main()
{cin>>n;
bktr(1);
}

You might also like