-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathuva-11003.cpp
More file actions
52 lines (41 loc) · 1.21 KB
/
uva-11003.cpp
File metadata and controls
52 lines (41 loc) · 1.21 KB
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
//uva 11003
//Boxes
#include <iostream>
#include <vector>
using namespace std;
int main(void)
{
int n = 0;
while (true) {
cin >> n;
if (!n)
break;
vector < pair <int, int> > boxes;//first = weight, second = load
int max_load = 0;
for (int i = 0; i < n; ++i){
int x, y;
cin >> x >> y;
max_load = max(max_load, y);
boxes.push_back(make_pair(x, y));
}
vector < vector <int> > arr(n, vector <int> (max_load + 1, 0));
arr[0][boxes[0].second] = 1;
for (int i = 1; i < n; ++i){
arr[i][boxes[i].second] = 1;
for (int j = 0; j < max_load + 1; ++j)
if (arr[i - 1][j] != 0){
arr[i][j] = max(arr[i][j], arr[i - 1][j]);
if (j - boxes[i].first >= 0){
int load = min(j - boxes[i].first, boxes[i].second);
arr[i][load] = max(arr[i][load], arr[i - 1][j] + 1);
}
}
}
int maxBox = 0;
for (auto a : arr[n - 1])
if (a > maxBox)
maxBox = a;
cout << maxBox << endl;
}
return 0;
}