yyyyyyy @ 2017-08-25 14:28:17
uses math;
var i,j,n,m,p:longint;
a:array[1..60,1..2] of longint;
w,c:array[0..60] of longint;
b:array[1..60] of -1..2;
f:array[1..32000] of longint;
begin
{assign(input,'happy.in');
assign(output,'happy.out');
reset(input);
rewrite(output);}
readln(m,n);
for i:=1 to n do
begin
readln(c[i],w[i],p);
if p>0 then
begin
inc(b[p]);
a[p,b[p]]:=i;
b[i]:=-1;
end;
end;
for i:=1 to n do
for j:=m downto 0 do
if (j-c[i]>=0)and(b[i]>-1) then
begin
f[j]:=max(f[j],f[j-c[i]]+c[i]*w[i]);
f[j]:=max(f[j],f[j-c[i]]+c[i]*w[i]+c[a[j,1]]*w[a[j,1]]);
f[j]:=max(f[j],f[j-c[i]]+c[i]*w[i]+c[a[j,2]]*w[a[j,2]]);
f[j]:=max(f[j],f[j-c[i]]+c[i]*w[i]+c[a[j,1]]*w[a[j,1]]+c[a[j,2]]*w[a[j,2]]);
end;
write(f[m]);
close(input);
close(output);
end.
by dashuaibifqw @ 2017-08-25 15:46:29
我敢肯定你程序错了
by dashuaibifqw @ 2017-08-27 22:46:34
To be or not to be, this is a question.
by dashuaibifqw @ 2017-08-27 22:47:19
Do you know?
by RyanFox @ 2017-09-25 20:49:54
@dashuaibifqw this is two questions.
by B_Qu1e7 @ 2018-03-17 17:23:22
@dashuaibifqw 怕不是莎比