- 开心的金明
- 2015-11-05 20:53:11 @
var n,m,i,j:longint;
v,p,s1:array[1..25] of longint; s:array[0..30000,1..25] of int64;
function g(x,y:int64):int64;
begin
if x>y then g:=x
else g:=y;
end;
begin
readln(n,m);
for i:=1 to m do
readln(v[i],p[i]);
for j:=1 to m do
for i:=1 to n do
if (i>=v[j]) then s[i,j]:=g(s[i-v[j],j-1]+v[j]*p[j],s[i,j-1])
else s[i,j]:=s[i,j-1];
write(s[n,m])
end.
2 条评论
-
佐之风 LV 8 @ 2015-11-05 21:14:02
状态转移方程错了
-
2015-11-05 20:59:59@
var
i,j,n,m,l,k:longint;
a,b,f:array[1..30000] of longint;
begin
readln(m,n);
for i:=1 to n do
begin
readln(a[i],b[i]);
b[i]:=b[i]*a[i];
end;
for i:=1 to n do
for j:=m downto 1 do
if j>=a[i] then
begin
if f[j]<f[j-a[i]]+b[i] then
f[j]:=f[j-a[i]]+b[i];
end;
writeln(f[m]);
end.
出自fangkechen
- 1