| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
过了CEOI的数据...而这里的过不了...是什么问题...可以看看不?program poj1717;
var
f0,f1:Array[-7000..7000] of longint;
n,i,j,a,b:integer;
w:Array[1..1000] of integer;
function min(a,b:longint):longint;
begin
if a<b then min:=a else min:=b;
end;
begin
readln(n);
for i:=1 to n do
begin
readln(a,b);
w[i]:=a-b;
end;
for i:=-7000 to 7000 do
f1[i]:=maxint;
f1[w[1]]:=0;
f1[-w[1]]:=1;
for i:=2 to n do
begin
fillchar(f0,sizeof(f0),0);
for j:=-6000 to 6000 do
f0[j]:=min(f1[j-w[i]],f1[j+w[i]]+1);
f1:=f0;
end;
for j:=0 to 6000 do
if (f0[j]<>maxint) or (f0[-j]<>maxint) then
begin
writeln(min(f0[j],f0[-j]));
halt;
end;
end.
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator