-
Notifications
You must be signed in to change notification settings - Fork 34
/
1017-Brush-III.cpp
114 lines (79 loc) · 1.37 KB
/
1017-Brush-III.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <iostream>
#include <stdio.h>
#include <map>
#include <algorithm>
#include <string.h>
using namespace std;
int n;
int k;
int w;
int ans[110][110][110];
struct node
{
int val;
int count;
};
node a[200];
bool epic(node x, node y)
{
if(x.val < y.val) {
return 1;
}
return 0;
}
int explore(int start, int end, int count)
{
if(end == n) {
return 0;
}
if(count == k) {
return 0;
}
if(ans[start][end][count] != -1) {
return ans[start][end][count];
}
if(a[end].val - a[start].val <= w) {
if(start == end) {
return ans[start][end][count] = max(a[end].count + explore(start, end+1, count), explore(end+1, end+1, count));
}
else {
return ans[start][end][count] = a[end].count + explore(start, end+1, count);
}
}
else {
return ans[start][end][count] = explore(end, end, count + 1);
}
}
int main()
{
int t;
int x;
int y;
int tot;
scanf("%d", &t);
for (int cs = 1; cs <= t; cs++) {
scanf("%d", &tot);
scanf("%d", &w);
scanf("%d", &k);
map <int, int> q;
memset(ans, -1, sizeof(ans));
n = 0;
for (int i = 0; i < tot; i++) {
scanf("%d", &x);
scanf("%d", &y);
if(q.count(y) == 0) {
node temp;
temp.val = y;
temp.count = 1;
q[y] = n;
a[n] = temp;
n++;
}
else {
a[q[y]].count++;
}
}
sort(a, a + n, epic);
printf("Case %d: %d\n", cs,explore(0, 0, 0));
}
}