题意
在规定的时间内,可以采到的草药的最大总价值。
分析
设 f[i,j]表示前i件物品,总重量不超过j的最优价值
则 f[i,j]=max{f[i-1,j-w[i]]+P[i],f[i-1,j])(1<=i<=m,1<=j<=t,j>=w[i])顺推
F[m,t]即为最优解var
t,m,i,j:longint;
w:array[1..1000]of longint;
p:array[1..100]of longint;
f:array[0..100,0..1000]of longint;
begin
read(t);read(m);
for i:=1 to m do
readln(w[i],p[i]);
fillchar(f,sizeof(f),0);
for i:=1 to m do
begin
for j:=1 to t do
begin
f[i,j]:=f[i-1,j];
if (w[i]<=j)and(f[i,j]<=f[i-1,j-w[i]]+p[i]) then f[i,j]:=f[i-1,j-w[i]]+p[i];
end;
end;
write(f[m,t]);
end.