728x90
https://www.acmicpc.net/problem/14500
14500번: 테트로미노
폴리오미노란 크기가 1×1인 정사각형을 여러 개 이어서 붙인 도형이며, 다음과 같은 조건을 만족해야 한다. 정사각형은 서로 겹치면 안 된다. 도형은 모두 연결되어 있어야 한다. 정사각형의 변
www.acmicpc.net
NxM 종이 위에 테트로미노 하나를 놓으려고 한다.
테트로미노 하나를 놓아서 테트로미노가 놓인 칸에 쓰여있는 수들의 합을 최대로 하는 프로그램 작성
회전이나 대칭 가능
모든 경우를 세서 배열로 만들어줬다. 이렇게 하면 완전 탐색으로 가능하다!
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <stack>
using namespace std;
int n, m, ans = 0;
int arr[505][505];
pair<int, int> t[19][4] = {
//case1
{{0, 0}, {0, 1}, {0, 2}, {0, 3}}, //좌표 찍음
{{0, 0}, {1, 0}, {2, 0}, {3, 0}},
//case2
{{0, 0}, {0, 1}, {1, 0}, {1, 1}},
//case3
{{0, 0}, {1, 0}, {2, 0}, {2, 1}},
{{0, 1}, {1, 1}, {2, 0}, {2, 1}},
{{1, 0}, {1, 1}, {1, 2}, {0, 2}},
{{0, 0}, {0, 1}, {1, 0}, {2, 0}},
{{0, 0}, {0, 1}, {1, 1}, {2, 1}},
{{0, 0}, {1, 0}, {1, 1}, {1, 2}},
{{0, 0}, {0, 1}, {0, 2}, {1, 0}},
{{0, 0}, {0, 1}, {0, 2}, {1, 2}},
//case4
{{0, 0}, {1, 0}, {1, 1}, {2, 1}},
{{0, 1}, {1, 0}, {1, 1}, {2, 0}},
{{0, 1}, {0, 2}, {1, 0}, {1, 1}},
{{0, 0}, {0, 1}, {1, 1}, {1, 2}},
//case5
{{0, 0}, {0, 1}, {0, 2}, {1, 1}},
{{0, 1}, {1, 0}, {1, 1}, {2, 1}},
{{0, 0}, {1, 0}, {1, 1}, {2, 0}},
{{0, 1}, {1, 1}, {1, 0}, {1, 2}}
};
int solution(int x, int y){
int maxV = 0;
for(int i=0; i<19; i++){
int sum = 0;
for(int j=0; j<4; j++) sum += arr[x + t[i][j].first][y + t[i][j].second];
maxV = max(maxV, sum);
}
return maxV;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i=0; i<n; i++) for(int j=0; j<m; j++) cin >> arr[i][j];
for(int i=0; i<n; i++) for(int j=0; j<m; j++) ans = max(ans, solution(i, j));
cout << ans << '\n';
return 0;
}
728x90
'알고리즘 > 백준' 카테고리의 다른 글
[백준/swift] 13300번: 방 배정 (0) | 2022.12.13 |
---|---|
[백준/swift] 1475번: 방 번호 (0) | 2022.12.13 |
[백준/c++] 3190번: 뱀 (0) | 2022.11.23 |
[백준/c++] 5427번: 불 (0) | 2022.11.17 |
[백준/c++] 14499번: 주사위 굴리기 (0) | 2022.11.16 |