Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <vector>
- #include <string>
- #include <algorithm>
- using namespace std;
- void gen(int n, int sum, vector<int> a, vector<int> b, vector<vector<int>> &answ) {
- if (n == sum) {
- b = a;
- sort(b.begin(), b.end());
- reverse(b.begin(), b.end());
- answ.push_back(b);
- }
- int na = 1;
- if (sum != 0) {
- na = a.back();
- }
- for (int i = na; i <= n - sum; i++) {
- a.push_back(i);
- gen(n, sum + i, a, b, answ);
- a.pop_back();
- }
- }
- int main() {
- int n;
- vector<vector<int>> answ;
- vector<int> a, b;
- ifstream in("input.txt");
- ofstream out("output.txt");
- in >> n;
- gen(n, 0, a, b, answ);
- sort(answ.rbegin(), answ.rend());
- reverse(answ.begin(), answ.end());
- for (int j = 0; j < answ.size(); j++) {
- for (int i = 0; i < answ[j].size(); i++) {
- out << answ[j][i] << ' ';
- }
- out << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement