提交时间:2023-08-24 10:14:09

运行 ID: 99903

#include <iostream> using namespace std; int a[105],cnt; int n; int sp[105]; void dfs(int tot,int size){ if (tot==n){ cnt++; cout << n << "="; for (int i = 1;i<size;i++){ cout << sp[i] << "+"; } cout << sp[size] << endl; } for (int i = max(sp[size],1);i+tot<=n&&i<n;i++){ sp[size+1]=i; dfs(tot+i,size+1); } } int main(){ cin >> n; dfs(0,0); cout << cnt; }