Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <set>
- #include <map>
- #include <iterator>
- #include <cmath>
- #include <string>
- #define ll long long
- using namespace std;
- void permutationSum(vector<int>& v, int n, int last) {
- if (n == 0) {
- for (auto i : v) {
- cout << i << " ";
- }
- cout << '\n';
- return;
- }
- for (int i = 1; i <= last; i++) {
- if (n - i < 0) {
- break;
- }
- v.push_back(i);
- permutationSum(v, n - i, i);
- v.pop_back();
- }
- }
- signed main() {
- // ios_base::sync_with_stdio(0);
- // cin.tie(0);
- // cout.tie(0);
- freopen("filename", "r", stdin);
- freopen("out_filename", "w", stdout);
- int n;
- cin >> n;
- vector<int> v;
- permutationSum(v, n, n + 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment