Advertisement
tanasaradu

Untitled

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