-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboxes_UVA11003.cpp
76 lines (64 loc) · 1.56 KB
/
boxes_UVA11003.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <bits/stdc++.h>
using namespace std;
ifstream fin("boxes_UVA11003.in");
ofstream fout("boxes_UVA11003.out");
const int inf = INT_MAX / 2;
const int N = 6005;
struct box
{
int m;
int l;
};
box _box(int m, int l)
{
box temp{m, l}; return temp;
}
int main()
{
int o=1;
while (true)
{
int n = 0; fin >> n;
if (n == 0) break;
if(o==135)
{
break;
}
++o;
vector<box> a(n);
for (int i = 0; i <= n - 1; ++i)
{
fin >> a[i].m >> a[i].l;
}
int ans = 1;
vector<vector<int>> dp(n, vector<int>(N + 1, -1 * inf)); dp[n - 1][a[n - 1].m] = 1;
for (int i = n - 2; i >= 0; --i)
{
for (int j = 0; j <= N; ++j)
{
dp[i][a[i].m] = 1;
if (a[i].l >= j - a[i].m && j >= a[i].m)
{
dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - a[i].m] + 1);
}
else
{
dp[i][j] = dp[i + 1][j];
}
ans = max(ans, dp[i][j]);
}
}
for (int i = n - 1; i >= 0; --i)
{
for (int j = a[i].m; j <= N; ++j)
{
if (dp[i][j] >= 0)
{
fout << "dp[" << i << "][" << j << "] = " << dp[i][j] << '\n';
}
}
}
fout << ans << '\n';
}
return 0;
}