讨论 / Pascal AC100
18151235220 2017-07-12 21:18:18
点我顶贴 收藏 删除
var

t,m,i,j:longint;

ti,c:array[1..100] of longint;

f:array[0..1001,0..1001]of longint;

begin

readln(t,m);

for i:=1 to m do

readln(ti[i],c[i]);

fillchar(f,sizeof(f),0);

for i:=1 to m do

for j:=1 to t do

begin

f[i,j]:=f[i-1,j];

if (j>=ti[i]) then if f[i-1,j-ti[i]]+c[i]>f[i,j] then f[i,j]:=f[i-1,j-ti[i]]+c[i];

end;

writeln(f[m,t]);

end.

查看更多回复
提交回复