- 小飞侠的游园方案
- 2014-11-06 21:05:47 @
var n,t,i,j,k,ans:integer;
fi,ti:array[1..100] of integer;
f:array[-1..1005] of integer;
function max(c,d:integer):integer;
begin
if c>d then exit(c) else exit(d);
end;
begin
read(n,t);
for i:=1 to n do read(fi[i],ti[i]);
for i:=1 to n do
for j:=t downto ti[i] do
begin
if f[j-ti[i]]+fi[i]>f[j] then
f[j]:=f[j-ti[i]]+fi[i];
end;
writeln(f[t]);
end.
上面用if判大小AC
var n,t,i,j,k,ans:integer;
fi,ti:array[1..100] of integer;
f:array[-1..1005] of integer;
function max(c,d:integer):integer;
begin
if c>d then exit(c) else exit(d);
end;
begin
read(n,t);
for i:=1 to n do read(fi[i],ti[i]);
for i:=1 to n do
for j:=ti[i] to t do
f[j]:=max(f[i-1,j],f[j-ti[i]]+fi[i]);
writeln(f[t]);
end.
这个用max函数只过了4个点,有什么区别吗?
1 条评论
-
Platypus LV 9 @ 2014-11-07 07:24:31
for i:=1 to n do
for j:=t downto ti[i] do //这个是01背包 要用downto
f[j]:=max(f[j],f[j-ti[i]]+fi[i]); //还有...一维二维混用是什么意思 = =
- 1