#Description
给你N个箱子,每个箱子有两个参数,就叫X,Y吧
你可以按顺序,顺序,这点很重要,X表示箱子多重,Y表示箱子承重多少
每个箱子上面的重量和不能超过他的承重
问最多放多少个箱子?
#Algorithm
DP
Dp[i]表示剩下承重是I
对于每新来一个东西j,参数是Xj,Yj
新承重t = min(I – Xj, Yj)
Dp[t] = max(Dp[t], Dp[i] + 1)
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
const int MAXV = 3000 + 9;
int n;
int dp[MAXV];
void solve()
{
memset(dp, 0, sizeof(dp));
int ans = 0;
for (int i = 0; i < n; i++) {
int a, b;
scanf("%d%d", &a, &b);
for (int j = 1; j < MAXV; j++) {
if (dp[j] > 0)
{
int t = min(j - a, b);
if (t < 0) continue;
dp[t] = max(dp[t], dp[j] + 1);
ans = max(dp[t], ans);
}
}
dp[b] = max(dp[b], 1);
ans = max(ans, 1);
}
printf("%d\n", ans);
}
int main()
{
//freopen("in.txt", "r", stdin);
for(;;) {
scanf("%d", &n);
if (n == 0) break;
solve();
}
}