• 문제 링크
20152번: Game Addiction
첫째 줄에 집과 PC방의 좌표 (H, H), (N, N) 을 나타내는 두 정수 H, N (0 ≤ H, N ≤ 30) 이 차례로 주어진다.
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int h = read(), n = read(), m = Math.abs(n - h);
long[][] dp = new long[m + 1][m + 1];
Arrays.fill(dp[0], 1);
for (int i = 1; i <= m; i++)
for (int j = i; j <= m; j++)
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
bw.write(String.valueOf(dp[m][m]));
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 1812 사탕 - Brute Force / Java (0) | 2023.10.02 |
---|---|
[백준] 9471 피사노 주기 - Brute Force / Java (0) | 2023.10.01 |
[백준] 17202 핸드폰 번호 궁합 - Dynamic Programming / Java (0) | 2023.09.29 |
[백준] 17291 새끼치기 - Dynamic Programming / Java (0) | 2023.09.28 |
[백준] 4172 sqrt log sin - Dynamic Programming / Java (0) | 2023.09.27 |
댓글