fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. long long a[10005], x = 0;
  4. int k;
  5. void dq(int n, int s)
  6. {
  7. if (k == 0) return;
  8. if (s == 0)
  9. {
  10. k--;
  11. for (int i = 1; i <= x; i++)
  12. {
  13. cout << a[i] << " ";
  14. }
  15. cout << 0 << endl;
  16. return;
  17. }
  18. if (n < 1) return;
  19. if (n <= s)
  20. {
  21. x++;
  22. a[x] = n;
  23. dq(n - 1, s - n);
  24. x--;
  25. }
  26. dq(n - 1, s);
  27. }
  28. int main()
  29. {
  30. int n, s; cin >> n >> k >> s;
  31. dq(n, s);
  32. }
  33.  
Success #stdin #stdout 0s 5324KB
stdin
6 2 10
stdout
6 4 0
6 3 1 0