解题思路:
注意事项:
参考代码:
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
int a[1000],t;
int n;
void dfs(int x,int s){
if(s>n){
return ;
}
if(s==n){
cout<<n;
for(int i=0;i<t;i++){
if(!i){
cout<<'='<<a[i];
}
else{
cout<<'+'<<a[i];
}
}
cout<<endl;
return ;
}
for(int i=x;i<n;i++){
a[t++]=i;
dfs(i,s+i);
a[--t]=0; //这里写--t没啥问题
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
dfs(1,0); //加数与和
return 0;
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:853 |
关于C语言变量位置的问题浏览:272 |
1050题解(结构体数组与结构体指针的使用)浏览:1106 |
Tom数 (C语言代码)浏览:525 |
用筛法求之N内的素数。 (C语言代码)浏览:529 |
永远的丰碑 (C语言代码)浏览:516 |
复数求和 (C语言代码)浏览:916 |
C语言程序设计教程(第三版)课后习题12.6 (C语言代码)浏览:649 |
10月月赛题解浏览:536 |
【魔板】 (C++代码)浏览:1156 |