Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int k,n,p,st[10];
- void init()
- {
- st[k]=0;
- }
- int succesor()
- {
- if(st[k]<n)
- {
- st[k]++;
- return 1;
- }
- return 0;
- }
- int valid()
- {
- int i;
- for(i=1;i<k;i++)
- if(st[i]==st[k])
- return 0;
- return 1;
- }
- int solutie()
- {
- int ok=0,i,nr=0;
- if(k==p)
- return 1;
- else
- return 0;
- }
- void tipar()
- {
- int i;
- for(i=1;i<=p;i++)
- cout<<st[i];
- cout<<endl;
- }
- void backt()
- {
- int as;
- k=1;
- init();
- while(k>0)
- {
- do
- {
- }while((as=succesor()) and !valid());
- if(as)
- {if(solutie())
- {tipar();}
- else
- {
- k++;
- init();
- }}
- else
- k--;
- }
- }
- main()
- {
- cin>>n>>p;
- backt();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement