Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #define NR 21
- using namespace std;
- int x[NR],n,p;
- char s[NR-1];
- void init(int k)
- {
- x[k]=0;
- }
- bool succesor(int k)
- {
- if (x[k]<n-p+k)
- return true;
- else
- return false;
- }
- bool continuare(int k)
- {
- if (k>1)
- if(x[k]<x[k-1])
- return false;
- for(int i=1;i<=k-1;++i)
- if(x[k]==x[i])
- return false;
- return true;
- }
- bool solutie(int k)
- {
- if(k==p+1)
- return true;
- else
- return false;
- }
- void afisare()
- {
- for(int i=1;i<=p;++i)
- cout<<s[x[i]-1];
- cout<<'\n';
- }
- void backtracking()
- {
- int k=1;
- init(1);
- while(k!=0)
- if(solutie(k))
- afisare(),--k;
- else
- if(succesor(k))
- {
- ++x[k];
- if(continuare(k))
- ++k;
- }
- else
- init(k),--k;
- }
- int main()
- {
- cin>>s>>n;
- p=strlen(s)-n;
- n=strlen(s);
- backtracking();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement