Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 |
Tags
- 문제해결
- 자바
- Java
- dfs
- 투포인터
- MySQL
- math
- BOJ
- 프로그래머스
- 알고리즘
- binary search
- greedy
- 코딩테스트
- SQL
- 코테
- SWEA
- DP
- 러닝일지
- BFS
- 백준
- 문자열
- 운동기록
- 이분탐색
- 문제풀이
- 건강
- 시뮬레이션
- oracle
- priorityqueue
- db
- COS PRO
Archives
- Today
- Total
슈콩
[BOJ] 14500 테트로미노 본문


[문제]
https://www.acmicpc.net/problem/14500
[소스 코드]
import java.io.*;
import java.util.*;
public class Main {
static int n,m,result;
static int[][] map;
static boolean[][] visit;
static int[] dr = {0,0,-1,1};
static int[] dc = {1,-1,0,0};
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
map = new int[n][m];
for(int i=0;i<n;i++) {
st = new StringTokenizer(br.readLine());
for(int j=0;j<m;j++) {
map[i][j] = Integer.parseInt(st.nextToken());
}
}
result = 0;
visit = new boolean[n][m];
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
visit[i][j] = true;
dfs(i,j,1,map[i][j]);
visit[i][j] = false;
}
}
System.out.println(result);
}
private static void dfs(int r,int c,int cnt,int sum) {
if(cnt==4) {
result = Math.max(result, sum);
return;
}
for(int d=0;d<4;d++) {
int nr = r + dr[d];
int nc = c + dc[d];
if(nr<0 || nr>=n || nc<0 || nc>=m) continue;
if(!visit[nr][nc]) {
visit[nr][nc] = true;
dfs(nr,nc,cnt+1,sum+map[nr][nc]);
if(cnt==2) dfs(r,c,cnt+1,sum+map[nr][nc]);
visit[nr][nc] = false;
}
}
}
}
'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 14502 연구소 (0) | 2025.12.01 |
|---|---|
| [BOJ] 14501 퇴사 (0) | 2025.12.01 |
| [BOJ] 14499 주사위 굴리기 (0) | 2025.11.30 |
| [BOJ] 13458 시험 감독 (0) | 2025.11.30 |
| [BOJ] 3190 뱀 (0) | 2025.11.30 |