堆栈溢出?

以下是我第一次提交的程序:

program p1059;

var

a:array[1..100,1..100]of longint;

p:array[1..101,0..10000]of boolean;

n,i,j:longint;

procedure makep(i,j:longint);

var

b:array[1..100]of longint;

x,y,k:longint;

f:array[0..100,0..10000]of boolean;

begin

fillchar(b,sizeof(b),0);

fillchar(f,sizeof(f),false);

for x:=1 to j do b[x]:=a;

for x:=0 to j do f[x,0]:=true;

for x:=1 to j do

for y:=0 to 10000 do

if y>=b[x] then f[x,y]:=f[x,y] or f[x-1,y] or f[x-1,y-b[x]]

else f[x,y]:=f[x,y] or f[x-1,y];

for x:=0 to 10000 do

if f[j,x] then

p:=true;

end;

begin

readln(n);

for i:=1 to n do

begin

j:=1;

read(a);

while a-1 do

begin

inc(j);

read(a);

end;

a:=0;

dec(j);

makep(i,j);

end;

i:=10000;

while i>=0 do

begin

for j:=1 to n+1 do

if not p[j,i] then break;

if j=n+1 then begin writeln(i);i:=0;end;

dec(i);

end;

end.

结果所有的数据都堆栈溢出,实在找不到原因,索性把过程移到主程序中,然后把过程删掉,就不会溢出了。就是不知道上面这个程序又没递归怎么会溢出?在自己电脑上运行会先输出答案,然后退出整个PASCAL,如果用单步运行会显示Program received signal SIGSEGV Segmentation fault。

以下是堆栈溢出的记录:

编译通过...

├ 测试数据 01:运行时错误...|错误号: 202

├ 测试数据 02:运行时错误...|错误号: 202

├ 测试数据 03:运行时错误...|错误号: 202

├ 测试数据 04:运行时错误...|错误号: 202

├ 测试数据 05:运行时错误...|错误号: 202

├ 测试数据 06:运行时错误...|错误号: 202

├ 测试数据 07:运行时错误...|错误号: 202

├ 测试数据 08:运行时错误...|错误号: 202

├ 测试数据 09:运行时错误...|错误号: 202

├ 测试数据 10:运行时错误...|错误号: 202

---|---|---|---|---|---|---|---|-

Unaccepted 有效得分:0 有效耗时:0ms

请问各位牛,这是为什么?

2 条评论

  • @ 2009-08-13 16:58:58

    长见识了,楼上的牛Orz啊~

  • @ 2009-08-12 10:04:25

    在过程里开的数组也是堆栈的……

    f:array[0..100,0..10000]of boolean;

    这个足矣爆栈……

  • 1

信息

ID
1059
难度
6
分类
动态规划 | 背包 点击显示
标签
(无)
递交数
7828
已通过
2342
通过率
30%
被复制
19
上传者