문제 링크입니다: https://programmers.co.kr/learn/courses/30/lessons/12905
코딩테스트 연습 - 가장 큰 정사각형 찾기
[[0,1,1,1],[1,1,1,1],[1,1,1,1],[0,0,1,0]] 9
programmers.co.kr
백준에도 똑같은 DP 문제가 있었던 것 같습니다.
(y, x) 기준으로 왼쪽, 좌상단, 위쪽 블록이 모두 1 이상이라면 정사각형의 일부라고 생각하면 됩니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
bool isZero(vector<vector<int>> &board) | |
{ | |
for (vector<int> b : board) | |
{ | |
for (int a : b) | |
{ | |
if (a) | |
{ | |
return false; | |
} | |
} | |
} | |
return true; | |
} | |
int solution(vector<vector<int>> board) | |
{ | |
if (isZero(board)) | |
{ | |
return 0; | |
} | |
int answer = 1; | |
for (int i = 1; i < board.size(); i++) | |
{ | |
for (int j = 1; j < board[i].size(); j++) | |
{ | |
if (!board[i][j]) | |
{ | |
continue; | |
} | |
board[i][j] = min({ board[i - 1][j], board[i][j - 1], board[i - 1][j - 1] }) + 1; | |
answer = max(answer, board[i][j] * board[i][j]); | |
} | |
} | |
return answer; | |
} |

개발환경: Programmers IDE
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > programmers' 카테고리의 다른 글
[Programmers] [3차] 파일명 정렬 (0) | 2022.02.25 |
---|---|
[Programmers] [3차] 압축 (0) | 2022.02.25 |
[Programmers] 방금그곡 (0) | 2022.02.16 |
[Programmers] 캐시 (0) | 2022.02.14 |
[Programmers] [1차] 프렌즈4블록 (0) | 2022.02.14 |