讨论 / wa30求找错
wsadjkl555 2013-12-30 13:36:22
点我顶贴 收藏 删除
var i,j,k,m,n,ans,l,r:longint;

f,w,a:array[0..40000] of longint;

function max(x,y:longint):longint;

begin

if x>y then exit(x) else exit(y);

end;

begin

readln(n,m);

for i:=1 to m do begin

readln(w[i],a[i],l);

a[i]:=a[i]*w[i];

if l<>0 then

begin

w[i]:=w[i]+w[l];

a[i]:=a[i]+a[l];

end;

end;

for i:=1 to m do

begin

for j:=n downto w[i] do

f[j]:=max(f[j],f[j-w[i]]+a[i]);

end;

writeln(f[n]);

end.

查看更多回复
提交回复