You are on page 1of 1

#include<iostream.

h>
int n,sol=0,x[100],i,j;
void BKT()
{
int k;
k=1;
init();
while(k>0)
if(exista(k))
{
x[k]=x[k+1];
if(valid(k))
if(solutie(k))
tipar(k);
else
{
k=k+1;
INIT();
}
}else k=k-1;
}
void citire()
{
cout<<"n= ";cin>>n;
}
void init(int k)
{
x[k]=0;
}
int exista(int k)
{
if(x[k]<n) return 1;
else return 0;
}
int valid(int k)
{
int i;
for(i=1;i<=k-1;i++)
if(x[i]=x[k]) return 0;
return 1;
}
int solutie(int k)
{
if(k==n) return 1;
else return 0;
}
void tipar(int k)
{
sol++;
cout<<"solutia "<<sol<<" : ";
for(i=1;i<=k;i++)
cout<<x[i]<<" ";
cout<<endl;
}
int main()
{
citire();
bkt();
}

You might also like