Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //aranjamente
- #include <iostream>
- using namespace std;
- int x[200],n,k,p;
- int cont(int k)
- {
- for(int i=1;i<k;i++)
- {
- if(x[i]==x[k])
- return 0;
- }
- return 1;
- }
- void tipar(int k)
- {
- for(int i=1;i<=k;i++)
- {
- cout<<x[i]<<" ";
- }
- cout<<endl;
- }
- void bkt()
- {
- k=1;
- x[k]=0;
- while(k>0)
- {
- if(x[k]<n)
- {
- x[k]++;
- if(cont(k))
- {
- if(k==p)
- tipar(k);
- else
- {
- k++;
- x[k]=0;
- }
- }
- }
- else k--;
- }
- }
- int main()
- {
- cin>>n>>p;
- bkt();
- return 0;
- }
- //combinari
- #include <iostream>
- using namespace std;
- int x[200],n,k,p;
- int cont(int k)
- {
- /* for(int i=1;i<k;i++)
- {
- if(x[i]>=x[k])
- return 0;
- }*/
- return 1;
- }
- void tipar(int k)
- {
- for(int i=1;i<=k;i++)
- {
- cout<<x[i]<<" ";
- }
- cout<<endl;
- }
- void bkt()
- {
- k=1;
- x[k]=0;
- while(k>0)
- {
- if(x[k]<n)
- {
- x[k]++;
- if(cont(k))
- {
- if(k==p)
- tipar(k);
- else
- {
- k++;
- x[k]=x[k-1];
- }
- }
- }
- else k--;
- }
- }
- int main()
- {
- cin>>n>>p;
- bkt();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement