Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream cin ("aranjamente.in");
- ofstream cout ("aranjamente.out");
- int st[20],n,p;
- void succesor (int k, int &as)
- {
- if (st[k]<n)
- {
- as=1;
- st[k]++;
- }
- else as=0;
- }
- void valid (int k, int &ev)
- {
- ev=1;
- for (int i=1; i<k; i++)
- if (st[i]==st[k])
- ev=0;
- }
- int solutie (int k)
- {
- if (k==p)
- return 1;
- else return 0;
- }
- int tipar ()
- {
- for (int i=1; i<=p; i++)
- cout<<st[i]<<" ";
- cout<<endl;
- }
- int main()
- {
- int as,ev,k;
- cin>>n>>p;
- k=1;
- st[k]=0;
- while (k>0)
- {
- do
- {
- succesor (k,as);
- if (as==1)
- valid (k, ev);
- }
- while (as==1 && ev==0);
- if (as==1)
- if (solutie (k)==1)
- tipar ();
- else
- {
- k++;
- st[k]=0;
- }
- else k--;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement