题意
在不超过N元(可以等于N元)的前提下,使每件物品的价格与重要度的乘积的总和最大。
分析
设 f[i,j]表示前i件物品,总重量不超过j的最优价值
则 f[i,j]=max{f[i-1,j-w[i]]+P[i]*v[i],f[i-1,j])(1<=i<=m,1<=j<=n,j>=w[i])顺推
F[m,n]即为最优解var
n,m,i,j:longint;
w:array[1..30000]of longint;
p:array[1..25]of longint;
f:array[0..25,0..30000]of longint;
begin
read(n);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 n 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]*w[i]) then f[i,j]:=f[i-1,j-w[i]]+p[i]*w[i];
end;
end;
write(f[m,n]);
end.