-
Notifications
You must be signed in to change notification settings - Fork 0
/
1633_최고의팀만들기.cpp
41 lines (37 loc) · 914 Bytes
/
1633_최고의팀만들기.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
#include <bits/stdc++.h>
#define endl "\n"
#define MAX 1002
#define int long long
using namespace std;
typedef pair<int, int> p;
int N = 0;
int arr[MAX][2];
int cache[MAX][16][16];
int solve(int idx, int b_cnt, int w_cnt){
if(idx == N) return 0;
if(b_cnt == 15 && w_cnt == 15) return 0;
int &ret = cache[idx][b_cnt][w_cnt];
if(ret != -1) return ret;
// Skip
ret = max(ret, solve(idx + 1, b_cnt, w_cnt));
// White
if(w_cnt < 15)
ret = max(ret, solve(idx + 1, b_cnt, w_cnt + 1) + arr[idx][0]);
// Black
if(b_cnt < 15)
ret = max(ret, solve(idx + 1, b_cnt + 1, w_cnt) + arr[idx][1]);
return ret;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
memset(cache, -1, sizeof(cache));
int a, b;
while(cin >> a >> b){
arr[N][0] = a;
arr[N][1] = b;
N++;
}
cout << solve(0, 0, 0);
return 0;
}