joyemang33 @ 2016-04-03 17:05:56
var w,c:array[1..60,1..4]of longint;
s:array[1..60]of longint;
f:array[0..32000]of longint;
n,m,x,y,z,i,j,k:longint;
function max(a,b:longint):longint;
begin if a>b then exit(a) else exit(b); end;
begin
read(m,n);
for i:=1 to n do
begin
read(x,y,z);
if z=0 then
for j:=1 to 4 do begin w[i,j]:=w[i,j]+x; c[i,j]:=c[i,j]+y*x; inc(k); end
else
begin
inc(s[z]);
if s[z]=1 then begin w[z,2]:=w[z,2]+x; c[z,2]:=c[z,2]+y*x; end;
if s[z]=2 then begin w[z,3]:=w[z,3]+x; c[z,3]:=c[z,3]+y*x; end;
w[z,4]:=w[z,4]+x; c[z,4]:=c[z,4]+y*x;
end;
end;
n:=k;
for i:=1 to k do
for j:=m downto w[i,1] do
begin
f[j]:=max(f[j-w[i,1]]+c[i,1],f[j]);
if j>=w[i,2] then f[j]:=max(f[j-w[i,2]]+c[i,2],f[j]);
if j>=w[i,3] then f[j]:=max(f[j-w[i,3]]+c[i,3],f[j]);
if j>=w[i,4] then f[j]:=max(f[j-w[i,4]]+c[i,4],f[j]);
end;
write(f[m]);
end.
by 我是叶昊 @ 2017-04-08 22:48:09
我的程序
var
f:array[0..4000]of longint;
v,p:array[1..60,0..2]of longint;
i,j,n,m,q,o,t:longint;
begin
readln(n,m);n:=n div 10;
for i:=1 to m do
begin
readln(q,o,t);
if t=0 then t:=i;
for j:=0 to 2 do
if v[t,j]=0 then
begin
v[t,j]:=q div 10;
p[t,j]:=v[t,j]*o;
break;
end;
end;
for i:=1 to m do
if v[i,0]<>0 then
for j:=n downto 0 do
begin
if (j>=v[i,0])and(f[j]<f[j-v[i,0]]+p[i,0]) then
f[j]:=f[j-v[i,0]]+p[i,0];
if (j>=v[i,0]+v[i,1])and(f[j]<f[j-v[i,0]-v[i,1]]+p[i,0]+p[i,1]) then
f[j]:=f[j-v[i,0]-v[i,1]]+p[i,0]+p[i,1];
if (j>=v[i,0]+v[i,2])and(f[j]<f[j-v[i,0]-v[i,2]]+p[i,0]+p[i,2]) then
f[j]:=f[j-v[i,0]-v[i,2]]+p[i,0]+p[i,2];
if (j>=v[i,0]+v[i,1]+v[i,2])and(f[j]<f[j-v[i,0]-v[i,1]-v[i,2]]+p[i,0]+p[i,1]+p[i,2]) then
f[j]:=f[j-v[i,0]-v[i,1]-v[i,2]]+p[i,0]+p[i,1]+p[i,2];
end;
writeln(f[n]*10);
end.