Skip to content

Latest commit

 

History

History
32 lines (30 loc) · 653 Bytes

C++拆分自然数.md

File metadata and controls

32 lines (30 loc) · 653 Bytes

在这里插入图片描述

//Author:PanDaoxi
#include <iostream>
using namespace std;
int a[10001];
int output(int n){
	for(int i=1;i<=n;i++){
		if(i!=1) cout<<"+";
		cout<<a[i];
	}
	cout<<endl;
}
int calc(int n,int ans){
	for(int i=1;i<=n/2;i++){
		if(i>=a[ans-1]){
			a[ans]=i;
			a[ans+1]=n-i;
			output(ans+1);
			calc(n-i,ans+1);
		}
	}
}
int main(){
	int n;
	cin>>n;
	a[0]=0;
	calc(n,1);
}