Gidhub BE Developer

[Programmers] 땅따먹기

2018-07-25
goodGid

Problem

Problem URL : 땅따먹기


[1] Answer Code (18. 07. 25)


int dp[100000][4] = {0};

int solution(vector<vector<int> > land)
{
    int answer = 0;
    dp[0][0] = land[0][0];
    dp[0][1] = land[0][1];
    dp[0][2] = land[0][2];
    dp[0][3] = land[0][3];
    
    for(int i=1; i<land.size(); i++){
        for(int j=0; j<4; j++){
            for(int k=0; k<4; k++){
                if( j==k ) continue;
                dp[i][j] = max(dp[i][j], dp[i-1][k] + land[i][j]);
                answer = max(answer, dp[i][j]);
            }
        }
    }
    
    return answer;
}


[1] Answer Code (18. 07. 25)

  • 기본적이 DP문제

Recommend

Index