提交时间:2024-04-16 16:45:24
运行 ID: 143563
#include<bits/stdc++.h> using namespace std; int n,ans,a[1000001]; void dfs(int step,int sum,int minn){ if(sum==n){ cout<<n<<"="; for(int i=1;i<step-1;i++)cout<<a[i]<<"+"; cout<<a[step-1]<<endl; ans++; return; } if(sum>=n)return; for(int i=minn;i<n;i++){ a[step]=i; dfs(step+1,sum+i,max(minn,i)); a[step]=0; } } int main(){ cin>>n; dfs(1,0,1); cout<<ans; return 0; }