You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
587 B

#include <bits/stdc++.h>
using namespace std;
int cnt;
vector<int> path;
void dfs(int n) {
if (n == 0) {
for (int i = 0; i < path.size(); i++) {
cout << path[i];
if (i < path.size() - 1) cout << "+";
}
cout << endl;
cnt++;
return;
}
for (int i = path.empty() ? 1 : path.back(); i <= n; i++) {
path.push_back(i);
dfs(n - i);
path.pop_back();
}
}
int main() {
int n;
cin >> n;
dfs(n);
cout << "total=" << cnt << endl;
return 0;
}