讨论 / 逃亡的准备 98题,多重背包,求让贪心不可以过的数据
神经病有所好转 2011-10-25 03:14:00
点我顶贴 收藏 删除
逃亡的准备

状态: Accepted

测评机: Xeost[5]

得分: 100分 [我要评价一下题目~]

提交日期: 2011-10-25 18:11:00

有效耗时: 2406毫秒

测试结果1: 通过本测试点|有效耗时297ms

测试结果2: 通过本测试点|有效耗时171ms

测试结果3: 通过本测试点|有效耗时172ms

测试结果4: 通过本测试点|有效耗时188ms

测试结果5: 通过本测试点|有效耗时156ms

测试结果6: 通过本测试点|有效耗时172ms

测试结果7: 通过本测试点|有效耗时266ms

测试结果8: 通过本测试点|有效耗时281ms

测试结果9: 通过本测试点|有效耗时344ms

测试结果10: 通过本测试点|有效耗时359ms

var i,j,k,t,nn,vv,temp:longint;

f:array[0..500]of longint;

v,c,n,test:array[0..6000]of longint;

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

begin max:=x; if x<y then max:=y;end;

begin

readln(nn,vv);

for i:=1 to nn do

begin

readln(n[i],v[i],c[i]);

test[i]:=c[i] div v[i];

end;

for i:=1 to nn-1 do

for j:=1 to nn-i do

if (test[j]<test[j+1]) then begin

t:=test[j]; test[j]:=test[j+1]; test[j+1]:=t;

t:=n[j]; n[j]:=n[j+1]; n[j+1]:=t;

t:=v[j]; v[j]:=v[j+1]; v[j+1]:=t;

t:=c[j]; c[j]:=c[j+1]; c[j+1]:=t;

end;

for i:=3 to nn do if n[i]>20 then n[i]:=20;

f[0]:=0;

for i:=1 to nn do

for j:=vv downto 0 do

for k:=1 to n[i] do

if j>=k*v[i] then

f[j]:=max(f[j-k*v[i]]+k*c[i],f[j]);

write(f[vv]);

end.

查看更多回复
提交回复