提交时间:2023-08-24 09:43:12

运行 ID: 99869

#include <bits/stdc++.h> using namespace std; int ans[114]; int n; int cnt = 0; void dfs(int x, int y) { if(x==1) { ans[y]=1; cout << n << "=" << ans[1]; cnt++; for(int k = 2; k <= y; k++) { cout << '+' << ans[k]; } cout << endl; } else { for(int j = ans[y-1]; j <= x/2; j++) { ans[y] = j; dfs(x-j,y+1); } ans[y]=x; cout << n << "=" << ans[1]; cnt++; for(int k = 2; k <= y; k++) { cout << '+' << ans[k]; } cout << endl; } } signed main() { cin >> n; for(int i = 1; i <= n/2; i++) { ans[1]=i; dfs(n-i,2); } cout << cnt << endl; return 0; }