#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<vector<int> > land)
{
int answer = 0;
vector<int> temp;
for(int i=0; i<land.size()-1; i++){
temp = land[i];
temp.erase(temp.begin()+0);
land[i+1][0]+= *max_element(temp.begin(),temp.end());
temp = land[i];
temp.erase(temp.begin()+1);
land[i+1][1]+= *max_element(temp.begin(),temp.end());
temp = land[i];
temp.erase(temp.begin()+2);
land[i+1][2]+= *max_element(temp.begin(),temp.end());
temp = land[i];
temp.erase(temp.begin()+3);
land[i+1][3]+= *max_element(temp.begin(),temp.end());
}
answer+= *max_element(land[land.size()-1].begin(),land[land.size()-1].end());
return answer;
}
// 12ms 나옴
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int get_max(int a, int b, int c){
if(a>b){
if(b>c){
return a;
}else{
if(a>c){
return a;
}else{
return c;
}
}
}else if(b>c){
return b;
}else if(c>b){
if(a>c){
return a;
}else{
return c;
}
}
}
int solution(vector<vector<int> > land)
{
int answer = 0;
for(int i=0; i<land.size()-1; i++){
land[i+1][0]+= get_max(land[i][1],land[i][2], land[i][3]);
land[i+1][1]+= get_max(land[i][0],land[i][2], land[i][3]);
land[i+1][2]+= get_max(land[i][1],land[i][0], land[i][3]);
land[i+1][3]+= get_max(land[i][1],land[i][2], land[i][0]);
}
answer+= *max_element(land[land.size()-1].begin(),land[land.size()-1].end());
return answer;
}
//6ms --> 반으로 줄어 들었다 벡터에 복사해서 지우고 찾는거 보다 함수 구현하니깐 반으로 줄었다.
** 거꾸로 생각하기
** 겹치는 열빼고 큰수 구하기로
** 그 큰수를 더해서 차근차근 큰수 구하기
'알고리즘 일기' 카테고리의 다른 글
행렬 곱셈 구현 (0) | 2019.09.03 |
---|---|
피보나치 수열 // 동적 프로그래밍 (0) | 2019.09.03 |
프로그래머스 다음 큰 숫자 // 이진수 변환 // 시간초과됨(해결완료) (0) | 2019.09.03 |
행렬 경우의수 (0) | 2019.09.02 |
조합 (0) | 2019.09.02 |
댓글