You are on page 1of 3

#include <iostream>

using namespace std;

int n,m,p,q,k,ev,as, st[100];

void init()

{if(k==2) st[k]=0;

else st[k]=st[k-1];}

int succesor()

{if (st[k]<n-m+k)

{st[k]=st[k]+1; return 1;}

else return 0;}

int valid ()

{return st[k]!=p && st[k]!=q;}

int solutie ()

{return k==m;}

void tipar()

{for (int i=1;i<=m;i++)

cout<<st[i]<<" ";

cout<<endl;}

void bt()

k=2;

init();

while(k>1)

{as=1;ev=0;
while(as&&!ev)

{as=succesor();

if(as) ev=valid();}

if(as)

if(solutie()) tipar();

else {k++; init();}

else k--;}}

int main()

cout<<"n="; cin>>n;

cout<<"m=";cin>>m;

cout<<"p="; cin>>p;

cout<<"q=";cin>>q;

st[1]=p;

bt();}

You might also like