Advertisement
tanasaradu

Untitled

Nov 23rd, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int n,st[20],a[1001],L,S;
  4. void BACK(int top,int suma)
  5. {
  6. if(top==(L+1) && suma<=S)
  7. {
  8. for(int i=1;i<=L;i++)
  9. cout<<a[st[i]]<<" ";
  10. cout<<"\n";
  11. }
  12. else for(int i=1;i<=n && suma+a[i]<=S;i++)
  13. {
  14. st[top]=i;
  15. suma+=a[i];
  16. BACK(top+1,suma);
  17. suma-=a[i];
  18. }
  19. }
  20. int main()
  21. {
  22. cin>>n>>L>>S;
  23. for(int i=1;i<=n;i++)
  24. cin>>a[i];
  25. BACK(1,0);
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement