传送门
http://www.lydsy.com/JudgeOnline/problem.php?id=4247
题目大意
给定
n
个物品,每个物品都消耗1体积,但会增加
题解
dp[i,j]=max{dp[i−1,j],dp[i−1,j−a[i]+1]+b[i]}
注意处置
const
maxn=2005;
var
dp:array[0..maxn,0..2*maxn]of longint;
x,y:array[0..maxn]of longint;
i,j,k:longint;
n,m,ans:longint;
function max(a,b:longint):longint;
begin if a>b then exit(a) else exit(b); end;
procedure sort(l,r:longint);
var a,b,i,j:longint;
begin
i:=l; j:=r; a:=x[(l+r)div 2];
repeat
while x[i]>a do inc(i);
while a>x[j] do dec(j);
if not(i>j) then
begin
b:=x[i]; x[i]:=x[j]; x[j]:=b;
b:=y[i]; y[i]:=y[j]; y[j]:=b;
inc(i); dec(j);
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
begin
readln(n);
for i:=1 to n do
readln(x[i],y[i]);
sort(1,n); {x[i]}
for i:=0 to n do
for j:=0 to n+1 do
dp[i,j]:=-1000000000;
dp[0,1]:=0;
for i:=1 to n do
for j:=0 to n do
dp[i,j]:=max(dp[i-1,j],dp[i-1,max(0,j-x[i])+1]+y[i]);
ans:=0;
for i:=0 to n do
ans:=max(ans,dp[n,i]);
writeln(ans);
end.