-
Notifications
You must be signed in to change notification settings - Fork 0
/
scubadiv.cpp
55 lines (51 loc) · 1.08 KB
/
scubadiv.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
// Created by rishabhstr ツ
#include <iostream>
#include <cstring> //memset
#include <algorithm>
#include <bitset>
#include <string>
#include <vector>
#include <utility>
#include <cstdio>
#include <queue>
#include <cmath>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
int dp[1000][25][85], co[1000], cn[1000], cw[1000];
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
std::ios::sync_with_stdio(false);
cin.tie(NULL);
int test_cases, t, a, c;
cin >> test_cases;
while (test_cases--) {
cin >> t >> a;
cin >> c;
for (int i = 0; i < c; ++i) {
cin >> co[i] >> cn[i] >> cw[i];
}
for (int i = 0; i <= c; i++) {
for (int j = 0; j <= t; j++) {
for (int k = 0; k <= a; k++) {
if (i == 0 || j == 0 || k == 0) {
dp[i][j][k] = 0;
}
else {
dp[i][j][k] = dp[i-1][j][k];
if (j >= co[i-1] && k >= cn[i-1]) {
dp[i][j][k] = max(dp[i][j][k], dp[i-1][j-co[i-1]][k-cn[i-1]]+cw[i-1]);
}
}
}
}
}
cout << dp[c][t][a] << endl;
}
return 0;
}