-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplates.cpp
More file actions
77 lines (70 loc) · 1.62 KB
/
plates.cpp
File metadata and controls
77 lines (70 loc) · 1.62 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
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
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int T, N, K, P;
vector<int> c;
vector<vector<int>> plates;
int answer;
int getPoints(vector<int> combi) {
int total = 0;
for (int i = 1; i <= N; i++) {
int a = combi[i];
for (int j = 1; j <= a; j++) {
total += plates[i][j];
}
}
return total;
}
vector<int> countCombi() {
vector<int> v(N+1);
for (int i = 1; i <= P; i++) {
v[c[i]]++;
}
return v;
}
//Combination with repitition
//n H p : getting combination of p in a set of n with repitition
void dfs(int index, int cnt) {
//if "cnt" exceeds "p", count number of the repeated
if (cnt == P+1) {
vector<int> combi = countCombi();
for (int i = 1; i <= N; i++) {
if (combi[i] > K) {
return;
}
}
int candi = getPoints(combi);
if (candi > answer) {
answer = candi;
}
return;
}
//else, pick every possible elements.
else {
for (int i = index; i <= N; i++) {
c[cnt] = i;
dfs(i, cnt + 1);
}
}
}
int main() {
cin >> T;
for (int t = 1; t <= T; t++) {
cin >> N >> K>>P;
answer = 0;
vector<vector<int>> plate(N+1);
for (int i = 1; i <= N; i++) {
vector<int> v(K+1);
for (int j = 1; j <= K; j++) {
cin >> v[j];
}
plate[i] = v;
}
plates = plate;
vector<int> v(P + 1);
c = v;
dfs(1, 1);
cout << "Case #" << t << ": " << answer << "\n";
}
}