提交时间:2023-11-04 09:10:41
运行 ID: 108655
#include <bits/stdc++.h> using namespace std; int n, ans; void dfs(string s, int lst, int sum) { if (sum == n) { cout << n << "=" << s << endl; ans++; return; } if (sum > n) return; for (int i=lst; i<n; i++) { string tmp; if (!s.empty()) tmp = s+"+"+(char)(i+'0'); else tmp = s+(char)(i+'0'); dfs(tmp, i, sum+i); } } int main() { // freopen("split.in", "r", stdin); // freopen("split.out", "w", stdout); cin >> n; dfs("", 1, 0); cout << ans; return 0; }