반응형
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 |
Tags
- 가운데 글자 가져오기 java
- 가운데 글자 가져오기 python
- 코드업 1020 java
- 가운데 글자 가져오기 파이썬
- docker 삭제
- 빅분기실기
- 코드업 1020 자바
- m1 docker install
- 프로그래머스 가운데 글자 가져오기 파이썬
- 나누어 떨어지는 숫자 배열 python
- docker 완전 삭제
- docker remove
- 최소 스패닝 트리 자바
- 트리의 지름 자바
- 최소 스패닝 트리
- 프로그래머스 나누어 떨어지는 숫자 배열 파이썬
- 핸즈온 머신러닝
- 프로그래머스 나누어 떨어지는 숫자 배열 자바
- 가운데 글자 가져오기 자바
- 빅데이터분석기사
- 나누어 떨어지는 숫자 배열 java
- 청년 AI Big Data 아카데미 13기
- 트리의 지름 java
- 프로그래머스 가운데 글자 가져오기 python
- m1 docker
- codeup 1020 자바
- 최단 경로 알고리즘
- 프로그래머스 가운데 글자 가져오기 자바
- codeup 1020 java
- 청년 Ai Big Data 아카데미
Archives
- Today
- Total
NineTwo meet you
[백준/자바] 2096 내려가기 본문
반응형

설명
슬라이딩 윈도 문제다.
i인덱스 일 때 첫 번째 숫자라면 i-1의 첫 번째와 두 번째를 비교한다.
i인덱스 일 때 두 번째 숫자라면 i-1의 첫 번째와 두 번째와 세 번째를 비교한다.
i인덱스 일 때 세 번째 숫자라면 i-1의 두 번째와 세 번째를 비교한다.
코드
This file contains 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
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.StringTokenizer; | |
public class BOJ2096 { | |
static int score[][][]; | |
public static void main(String[] args) throws IOException { | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
int n = Integer.parseInt(br.readLine()); | |
score = new int[n][3][3]; | |
for(int i = 0; i < n; i++) { | |
StringTokenizer st = new StringTokenizer(br.readLine()); | |
for(int j = 0; j < 3; j++) { | |
score[i][j][0] = Integer.parseInt(st.nextToken()); | |
} | |
} | |
for(int i = 0; i < 3; i++) { | |
score[0][i][2] = score[0][i][1] = score[0][i][0]; | |
} | |
for(int i = 1; i < n; i++) { | |
score[i][0][1] = Math.min(score[i-1][0][1], score[i-1][1][1]) + score[i][0][0]; | |
score[i][1][1] = Math.min(Math.min(score[i-1][0][1], score[i-1][1][1]), score[i-1][2][1]) + score[i][1][0]; | |
score[i][2][1] = Math.min(score[i-1][1][1], score[i-1][2][1]) + score[i][2][0]; | |
score[i][0][2] = Math.max(score[i-1][0][2], score[i-1][1][2]) + score[i][0][0]; | |
score[i][1][2] = Math.max(Math.max(score[i-1][0][2], score[i-1][1][2]), score[i-1][2][2]) + score[i][1][0]; | |
score[i][2][2] = Math.max(score[i-1][1][2], score[i-1][2][2]) + score[i][2][0]; | |
} | |
int max = Integer.MIN_VALUE; | |
int min = Integer.MAX_VALUE; | |
for(int i = 0; i < 3; i++) { | |
max = Math.max(max, score[n-1][i][2]); | |
min = Math.min(min, score[n-1][i][1]); | |
} | |
System.out.println(max+" "+min); | |
} | |
} |
반응형
'프로그래밍 문제 > 백준' 카테고리의 다른 글
[백준/자바] 18405 경쟁적 전염 (0) | 2021.10.10 |
---|---|
[백준/자바] 20061 모노미노도미노2 (0) | 2021.10.09 |
[백준/자바] 21611 마법사 상어와 블리자드 (0) | 2021.10.04 |
[백준/자바] 21610 마법사 상어와 비바라기 (0) | 2021.10.04 |
[백준/자바] 20058 마법사 상어와 파이어스톰 (0) | 2021.09.30 |