大神帮我看一下:(PID:127 纪念品分组)
program group;
var
w,n,i,j,ans,s,x,k:longint;
a:array[0..30001] of longint;
b:array[0..1001] of boolean;
r:array[0..1001] of longint;
begin
ans:=0;
fillchar(b,sizeof(b),false);
fillchar(r,sizeof(r),0);
readln(w);
readln(n);
for i:=1 to n do begin readln(x); inc(r[x]); end;
k:=0;
for i:=5 to 200 do if r[i]>0 then
for j:=1 to r[i] do begin inc(k); a[k]:=i; end;
for i:=n downto 1 do begin
s:=a[i]; if not b[i] then begin
for j:=1 to i-1 do begin
if (s+a[j]<=w) and (not b[j]) then begin
inc(s,a[j]); b[j]:=true; break; end else
if (s+a[j]>w) and (not b[j]) then break;
end;
inc(ans);
end;
end;
write(ans);
end.
我的悲惨结局:
状态: Unaccepted
测评机: Xeost[5]
得分: 50分
提交日期: 2013-7-10 14:32:00
有效耗时: 968毫秒
测试结果1: 通过本测试点|有效耗时219ms
测试结果2: 通过本测试点|有效耗时187ms
测试结果3: 通过本测试点|有效耗时188ms
测试结果4: 通过本测试点|有效耗时187ms
测试结果5:
测试结果6: 运行错误|普通保护错误
测试结果7: 选手程序运行超过时限
测试结果8: 运行错误|普通保护错误
测试结果9: 运行错误|普通保护错误
测试结果10: 通过本测试点|有效耗时187ms
数组定义小了,你的i是n downto 1 ,j 是1 to i-1,但是n 最大是30000,b数组只有1001,所以越界了