tchwr 2015-10-25 22:10:03
点我顶贴
收藏
删除
var c:array[1..30001]of longint;
w:array[1..30001]of integer;
V,max,i,j:longint;
n,open,closed:integer;
f:array[0..30001]of longint;
begin
read(V,n);
for i:=1 to n do read(c[i],w[i]);
fillchar(f,sizeof(f),0);
for i:=1 to n do
for j:=V downto c[i] do if f[j-c[i]]+w[i]>f[j] then f[j]:=f[j-c[i]]+w[i];
max:=0;
for i:=1 to V do if max<f[i] then max:=f[i];
write(max);
end.