drof13

Untitled

Nov 4th, 2021
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <set>
  5. #include <map>
  6. #include <iterator>
  7. #include <cmath>
  8. #include <string>
  9.  
  10. #define ll long long
  11.  
  12. using namespace std;
  13.  
  14. void permutationSum(vector<int>& v, int n, int last) {
  15.     if (n == 0) {
  16.         for (auto i : v) {
  17.             cout << i << " ";
  18.         }
  19.         cout << '\n';
  20.         return;
  21.     }
  22.     for (int i = 1; i <= last; i++) {
  23.         if (n - i < 0) {
  24.             break;
  25.         }
  26.         v.push_back(i);
  27.         permutationSum(v, n - i, i);
  28.         v.pop_back();
  29.     }
  30. }
  31.  
  32. signed main() {
  33.     // ios_base::sync_with_stdio(0);
  34.     // cin.tie(0);
  35.     // cout.tie(0);
  36.     freopen("filename", "r", stdin);
  37.     freopen("out_filename", "w", stdout);
  38.     int n;
  39.     cin >> n;
  40.     vector<int> v;
  41.     permutationSum(v, n, n + 1);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment