提交时间:2023-11-04 09:17:26

运行 ID: 108686

#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; if (n ==0) { cout << 0; return 0; } if (n ==1) { // cout << "1=1" << endl; cout << "0"; return 0; } dfs("", 1, 0); cout << ans; return 0; }