1318:【例5.3】自然数的拆分
作者:互联网
1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 5 const int N=105; 6 int n,a[N]; 7 8 void solve(int b,int s,int l){ 9 if(b>0){ 10 for(int i=s;i<=b;i++){ 11 a[l]=i; 12 solve(b-i,i,l+1); 13 } 14 }else{ 15 if(l>2){ 16 printf("%d=%d",n,a[1]); 17 for(int i=2;i<l;i++) 18 printf("+%d",a[i]); 19 cout<<endl; 20 } 21 } 22 } 23 int main(){ 24 cin>>n; 25 solve(n,1,1); 26 return 0; 27 }
标签:5.3,int,自然数,1318,solve,拆分,printf,include 来源: https://www.cnblogs.com/sxrekord/p/splitting_of_natural_numbers.html