讨论 / 求帮忙
875880923 2011-11-04 13:11:00
点我顶贴 收藏 删除
我是新手 完全背包 帮个忙

program ti;

const n=10;

var f:array[0..200]of longint;

c,w:array[1..10]of longint;

i,j,k,v:longint;

begin

for i:=1 to n do begin

read(w[i]); c[i]:=i; end;

readln(v);

fillchar(f,sizeof(f),maxlongint);

for i:=1 to n do

for j:=0 to v do begin

k:=0;

repeat

inc(k);

if (v-k*c[i])<0 then break

else if f[j]>f[j-k*c[i]]+k*w[i] then

f[j]:=f[j-c[i]]+w[i];

until true;

end;

writeln(f[v]);

end.

查看更多回复
提交回复