- 精卫填海(HOI)
- 2013-12-03 21:15:09 @
var k,m:array[0..10000] of longint;
f:array[0..10000] of longint;
i,j,n,v,c:longint;
function max(a,b:longint):longint;
begin
if a>b then exit(a) else exit(b);
end;
begin
readln(v,n,c);
for i:=1 to n do readln(k[i],m[i]);
for i:=1 to c do
for j:=c downto m[i] do
f[j]:=max(f[j-m[i]]+k[i],f[j]);
for i:=0 to c do if f[i]>=v then begin writeln(c-i);halt;end;
writeln('Impossible');
end.
为什么for i:=1 to c 有几个数据错 而 for i:=1 to n 就对
3 条评论
-
贱人在我右边 LV 9 @ 2017-03-01 08:01:38
那样的话就不对了,本题是01背包
-
2017-03-01 08:01:12@
如果是正着走就会变成完全背包
-
2014-10-17 13:26:10@
应该for物品。。去看看背包九讲吧。
- 1