프로그래머스 코테 고득점 kit / 최소직사각형 / C++ / 정렬, dfs, 최적화

jjin·2023년 10월 7일
0

2차원 vector 내부 정렬 문제 없지

for (vector<int> v : vs) {
	sort(v.begin(), v.end());
}

로컬 최적이 전체 최적. 최적 부분 구조?

#include <bits/stdc++.h>
using namespace std;

int solution(vector<vector<int>> sizes) {
    int w = 0;
    int h = 0;
    
    for (vector<int> size : sizes) {
        if (size[0] > size[1]) {
            w = max(w, size[0]);
            h = max(h, size[1]);
        }
        else {
            w = max(w, size[1]);
            h = max(h, size[0]);
        }
    }
    return w * h;
}
profile
진짜

0개의 댓글