提交时间:2023-11-04 09:23:38
运行 ID: 108709
#include<bits/stdc++.h> using namespace std; int n, p[11]={1}, m, cnt; void print(int aa){ for(int i=1; i<aa; i++) cout << p[i] << "+" ; cout << p [aa] << endl; } void dfs(int a){ for(int i=p[a-1]; i<=m; i++){ if(i == n) continue; p[a] = i; m -= i; if(m == 0){ print(a); cnt ++; } else dfs(a + 1); m += i; } } int main(){ cin >> n; m = n; dfs(1); cout << cnt; return 0; }