program NDK1503;
type atp=record
v,p,num:longint;
end;
var
n,m:longint;
a:array [1..60] of atp;
f:array [0..32000] of longint;
t1,t2:array [1..60] of atp;
procedure init;
var
i,tex:longint;
begin
readln(n,m);
for i:=1 to m do
begin
readln(a[i].v,a[i].p,tex);
a[i].num:=tex;
if tex<>0 then
begin
if t1[tex].v=0 then
begin
t1[tex].v:=a[i].v;
t1[tex].p:=a[i].p;
end
else
begin
t2[tex].v:=a[i].v;
t2[tex].p:=a[i].p;
end;
end;
end;
end;
function max(x,y:longint):longint;
begin
if x>y then exit(x) else exit(y);
end;
procedure main;
var
i,j,maxx:longint;
begin
for i:=1 to m do
begin
if a[i].num=0 then
begin
for j:=n downto 0 do
begin
if j-a[i].v>=0 then f[j]:=max(f[j],f[j-a[i].v]+a[i].v*a[i].p);//只选主件
if (t1[i].v<>0) and (j-a[i].v-t1[i].v>=0) then f[j]:=max(f[j],f[j-a[i].v-t1[i].v]+a[i].v*a[i].p+t1[i].v*t1[i].p);//选主件+附件1
if (t2[i].v<>0) then
begin
if j-a[i].v-t2[i].v>=0 then f[j]:=max(f[j],f[j-a[i].v-t2[i].v]+a[i].v*a[i].p+t2[i].v*t2[i].p);//选主件+附件2
if j-a[i].v-t1[i].v-t2[i].v>=0 then f[j]:=max(f[j],f[j-a[i].v-t1[i].v-t2[i].v]+a[i].v*a[i].p+t1[i].v*t1[i].p+t2[i].v*t2[i].p);//选主件+附件1+附件2
end;
end;
end;
end;
end;
begin
assign(input,'NDK1503.in'); reset(input);
assign(output,'NDK1503.out'); rewrite(output);
init;
main;
writeln(f[n]);
close(input); close(output);
end.
金明的预算方案 NDK1503 解题报告
最新推荐文章于 2025-04-29 18:49:19 发布