啊哈C++上过了,dev5.11也过了,上了洛谷直接0分
全是RE
Received signal 11: Segmentation fault with invalid memory reference.
越个界又能怎
请大家帮我找找哪里越界了
#include <bits/stdc++.h>
using namespace std;
int a[100001]={1};
int n;
int total=0;
int print(int tot);
int search(int s,int t);
int main(){
cin>>n;
search(n,1);
}
int search(int s,int t)
{
for (int i=a[t-1];i<=s;i++)
{
if (i<n)
{
s-=i;
a[t]=i;
if (s==0) print(t);
else search(s,t+1);
s+=i;
}
}
}
int print(int tot)
{
for (int i=1;i<=tot-1;i++)
{
printf("%d+",a[i]);
}
printf("%d\n",a[tot]);
total++;
}