Notice
Recent Posts
Recent Comments
Link
Dev.baelanche
[백준 14500] 테트로미노 본문
반응형
N*M 배열에서 테트로미노를 놓을 수 있는 경우를 모두 체크한다.
코드를 보면 구현방식을 아주 쉽게 알 수 있다.
public class Main {
static int a[][];
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
a = new int[n][m];
for(int i=0; i<n; i++) {
st = new StringTokenizer(br.readLine());
for(int j=0; j<m; j++)
a[i][j] = Integer.parseInt(st.nextToken());
}
int max = 0;
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
if(i+1 < n && j+2 < m) {
/* ㅁㅁ
* ㅁㅁ
*/
int sum = a[i][j] + a[i][j+1] + a[i+1][j+1] + a[i+1][j+2];
max = Math.max(max, sum);
/* ㅁㅁ
* ㅁㅁ
*/
sum = a[i][j+1] + a[i][j+2] + a[i+1][j] + a[i+1][j+1];
max = Math.max(max, sum);
/* ㅁㅁㅁ
* ㅁ
*/
sum = a[i][j] + a[i][j+1] + a[i][j+2] + a[i+1][j];
max = Math.max(max, sum);
/* ㅁㅁㅁ
* ㅁ
*/
sum = a[i][j] + a[i][j+1] + a[i][j+2] + a[i+1][j+2];
max = Math.max(max, sum);
/* ㅁ
* ㅁㅁㅁ
*/
sum = a[i][j] + a[i+1][j] + a[i+1][j+1] + a[i+1][j+2];
max = Math.max(max, sum);
/* ㅁ
* ㅁㅁㅁ
*/
sum = a[i][j+2] + a[i+1][j] + a[i+1][j+1] + a[i+1][j+2];
max = Math.max(max, sum);
/* ㅁ
* ㅁㅁㅁ
*/
sum = a[i][j+1] + a[i+1][j] + a[i+1][j+1] + a[i+1][j+2];
max = Math.max(max, sum);
/* ㅁㅁㅁ
* ㅁ
*/
sum = a[i][j] + a[i][j+1] + a[i+1][j+1] + a[i][j+2];
max = Math.max(max, sum);
}
if(i+2 < n && j+1 < m) {
/* ㅁ
* ㅁㅁ
* ㅁ
*/
int sum = a[i][j] + a[i+1][j] + a[i+1][j+1] + a[i+2][j+1];
max = Math.max(max, sum);
/* ㅁ
* ㅁㅁ
* ㅁ
*/
sum = a[i][j+1] + a[i+1][j] + a[i+1][j+1] + a[i+2][j];
max = Math.max(max, sum);
/* ㅁ
* ㅁ
* ㅁㅁ
*/
sum = a[i][j] + a[i+1][j] + a[i+2][j] + a[i+2][j+1];
max = Math.max(max, sum);
/* ㅁ
* ㅁ
* ㅁㅁ
*/
sum = a[i][j+1] + a[i+1][j+1] + a[i+2][j] + a[i+2][j+1];
max = Math.max(max, sum);
/* ㅁㅁ
* ㅁ
* ㅁ
*/
sum = a[i][j] + a[i][j+1] + a[i+1][j] + a[i+2][j];
max = Math.max(max, sum);
/* ㅁㅁ
* ㅁ
* ㅁ
*/
sum = a[i][j] + a[i][j+1] + a[i+1][j+1] + a[i+2][j+1];
max = Math.max(max, sum);
/* ㅁ
* ㅁㅁ
* ㅁ
*/
sum = a[i][j] + a[i+1][j] + a[i+1][j+1] + a[i+2][j];
max = Math.max(max, sum);
/* ㅁ
* ㅁㅁ
* ㅁ
*/
sum = a[i][j+1] + a[i+1][j] + a[i+1][j+1] + a[i+2][j+1];
max = Math.max(max, sum);
}
if(j+3 < m) {
/* ㅁㅁㅁㅁ
*/
int sum = a[i][j] + a[i][j+1] + a[i][j+2] + a[i][j+3];
max = Math.max(max, sum);
}
if(i+3 < n) {
/* ㅁ
* ㅁ
* ㅁ
* ㅁ
*/
int sum = a[i][j] + a[i+1][j] + a[i+2][j] + a[i+3][j];
max = Math.max(max, sum);
}
if(i+1 < n && j+1 < m) {
/* ㅁㅁ
* ㅁㅁ
*/
int sum = a[i][j] + a[i+1][j] + a[i][j+1] + a[i+1][j+1];
max = Math.max(max, sum);
}
}
}
System.out.println(max);
}
}
반응형
'Data Structure & Algorithm > PS - JAVA' 카테고리의 다른 글
[백준 2979] 트럭 주차 (0) | 2019.06.29 |
---|---|
[백준 1547] 공 (0) | 2019.06.29 |
[백준 6603] 로또 (0) | 2019.06.29 |
[백준 11866] 조세퍼스 문제 0 (0) | 2019.06.29 |
[백준 4949] 균형잡힌 세상 (0) | 2019.06.29 |
Comments