提交时间:2023-08-24 10:44:31

运行 ID: 99943

#include<bits/stdc++.h> using namespace std; int n, p[11]={1}, cnt=0, m; void print(int aa){ cout << n << "="; for(int i=1; i<aa; i++) cout << p[i] << "+" ; cout << p [aa] << endl; cnt ++; } 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); else dfs(a + 1); m += i; } } int main(){ cin >> n; m = n; dfs(1); cout << cnt; return 0; }