처음에 이걸 어떻게 해야하나 고민을 많이 했다.
배열을 만들어서 미리 값을 다 넣은 다음에 꺼내오는 형식으로 할까 해서 해 보았다.
다음 호수는 이전호수 + 아래층의 같은 호수라는 점을 이용했다.
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 32 33 34 35 36 37 38 | package baek2775; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); int testcase = Integer.parseInt(bf.readLine()); int k, n; Integer[][] building = new Integer[15][15]; for (int i = 0; i < 15; i++) { building[0][i] = i; } for (int i = 0; i < 15; i++) { building[i][0] = 0; } for (int i = 1; i < 15; i++) { for (int j = 1; j < 15; j++) { building[i][j] = building[i-1][j] + building[i][j-1]; } } for (int i = 0; i < testcase ; i++) { k = Integer.parseInt(bf.readLine()); n = Integer.parseInt(bf.readLine()); System.out.println(building[k][n]); } } } | cs |
정상적으로 잘 실행된다.
'알고리즘' 카테고리의 다른 글
백준 알고리즘 1978 - 소수 찾기 (0) | 2020.03.31 |
---|---|
백준 알고리즘 1011 - Fly me to the Alpha Centauri (0) | 2020.03.23 |
백준 알고리즘 10250 - ACM 호텔 (0) | 2020.03.20 |
댓글