#include <string>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAX = 101;
const int MAX2 = 100001;
int score[MAX][MAX2];
int solution(int k, vector<vector<int>> travel) {
score[0][travel[0][0]] = travel[0][1];
score[0][travel[0][2]] = travel[0][3];
for(int i=1; i<travel.size(); i++){
for(int j=0; j<=k; j++){
if(score[i-1][j] == 0)
continue;
if(j+travel[i][0] <=k)
score[i][j+travel[i][0]] = max(score[i][j+travel[i][0]],score[i-1][j]+travel[i][1]);
if(j+travel[i][2] <= k)
score[i][j+travel[i][2]] = max(score[i][j+travel[i][2]],score[i-1][j]+travel[i][3]);
}
}
int answer = -1;
for(int i=0; i<=k; i++)
answer = max(answer,score[travel.size()-1][i]);
return answer;
}
프로그래머스