本地运行把栈搞爆了,Segmentation fault,求调
查看原帖
本地运行把栈搞爆了,Segmentation fault,求调
1057966
youlunkubiaoke楼主2023/11/26 16:02

代码如下

#ifndef ONLINE_JUDGE
#pragma GCC optimize(3)
#include<windows.h>
#endif
#include<iostream>
using namespace std;
typedef long long int LL;
LL n,arr[100]={0};
void Print(LL Bit)
{
    for (LL n=1;n<Bit;n++)
    {
        cout<<arr[n];
        if (n!=Bit-1)
          cout<<"+";
    }
    cout<<endl;
}
void DFS(LL sum,LL Bit)
{
    if (sum==0)
    {
        Print(Bit);
        return;
    }
    for (LL n1=1;n1<n;n1++)
    {
        if (n1>=arr[Bit-1])
        {
            arr[Bit]=n1;
            sum=sum-n1;
            DFS(sum,Bit+1);
            sum=sum+n1;
        }
    }
    return;
}
int main()
{
    cin>>n;
    DFS(n,1);
    #ifndef ONLINE_JUDGE
    system("pause");
    #endif
    return 0;
}
2023/11/26 16:02
加载中...