像素


私信TA

用户名:dotcpp0735122

访问量:243

签 名:

落山

等  级
排  名 9657
经  验 1079
参赛次数 0
文章发表 12
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

TA的其他文章

解题思路:

注意事项:

参考代码:

#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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区