- 采药
- 2016-07-21 14:51:25 @
var
m,i,j,t:longint;
c,w:array[1..101] of longint;
f:array[0..101,0..1001] of longint;
Function max(a,b:longint):longint;
begin
if a>b then exit(a)
else exit(b);
end;
begin
readln(t,m);
for i:=1 to m do
readln(c[i],w[i]);
for i:=1 to m do
for j:=1 to t do
if j>=c[i] then
f[i,j]:=max(f[i-1,j],f[i-1,j-c[i]]+w[i]);
writeln(f[m,t]);
end.
5 条评论
-
cjoier_gjh LV 8 @ 2017-01-23 00:26:20
看数据范围啊,(1000*100)^2,你开二维试试?
-
2017-01-22 16:57:16@
var
w, v:array[1..100] of longint;
f:array[0..1000] of longint;
n, x, i, j:longint;
begin
readln(x, n);
for i:=1 to n do readln(w[i], v[i]);
fillchar(f, sizeof(f), 0);
for i:=1 to n do
for j:=x downto w[i] do if f[j-w[i]]+v[i]>f[j] then f[j]:=f[j-w[i]]+v[i];
write(f[x])
end. -
2016-10-24 18:34:14@
。。。正常
-
2016-10-03 12:29:54@
var
m,time:integer;
i,j,max:longint;
v,t:array[0..1001] of longint;
opt:array[0..1001] of longint;begin
read(time,m);
for i:=1 to m do
read(t[i],v[i]);fillchar(opt,sizeof(opt),0);
for i:=1 to m do
for j:=time downto t[i] do
if opt[j-t[i]]+v[i]>opt[j]
then opt[j]:=opt[j-t[i]]+v[i];max:=-maxlongint;
for i:=1 to time do
if opt[i]>max then max:=opt[i];
writeln(max);
end. -
2016-08-29 17:40:40@
if( j < c[i] ) f[i][j] = f[i-1][j];
- 1