提交时间:2023-08-24 10:02:42

运行 ID: 99887

#include <iostream> using namespace std; int lst[1024]; int pos = 0; int N; int sum = 0; void dfs(int num,int last) { if(num == 0) { sum++; cout << N << '='; for(int i = 0;i < pos - 1;i++) { cout << lst[i] << '+'; } cout << lst[pos - 1]; cout << endl; } else { for(int i = last;i <= num;i++) { if(i == N) continue; lst[pos++] = i; dfs(num - i,i); pos--; } } } int main() { cin >> N; dfs(N,1); cout << sum; }