提交时间:2023-12-12 13:49:49
运行 ID: 115606
#include<bits/stdc++.h> using namespace std; int ans=0,n,a[101]={1}; void print(int p){ p-=1; cout<<n<<"="; for(int i=1;i<=p-1;i++) cout<<a[i]<<"+"; cout<<a[p]<<'\n'; return; } void solve(int tot,int cmp){ if(tot==0){ print(cmp); ans++; return; } for(int i=a[cmp-1];i<=tot;i++){ if(i<n){ a[cmp]=i; tot-=i; solve(tot,cmp+1); tot+=i; } } } int main(){ cin>>n; solve(n,1); cout<<ans; return 0; }