프로그래머스
카드 게임 C++
by paysmile
2019. 10. 9.
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAX = 2001;
vector<int> l, r;
int score[MAX][MAX];
int maxsum(int x, int y) {
if (x >= l.size() || y >= r.size())
return 0;
int &value = score[x][y];
if (value != -1)
return value;
value = 0;
value = max(maxsum(x+1, y), maxsum(x+1, y+1));
if (l[x] > r[y]) {
value = max(value, r[y] + maxsum(x, y + 1));
}
return value;
}
int solution(vector<int> left, vector<int> right) {
l = left;
r = right;
memset(score, -1, sizeof(score));
return maxsum(0, 0);
}