

이것도 수열문제입니다. 0층의 i호에 i명이 산다고 했으니, 0층은 1호부터 1,2,3,4...명이 산다고 할 수 있죠.
그후 한층씩 올려가면서 규칙성을 파악하고, 수열로 생각하면서 규칙성에 맞는 k층 n호의 수를 구하면 됩니다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
int k, n; int[][] apt;
for (int i=0; i<t; i++) {
k = Integer.parseInt(br.readLine());
n = Integer.parseInt(br.readLine());
apt = new int[k+1][n];
for (int j=1; j<=n; j++) {
apt[0][j-1] = j;
}
for (int l=1; l<=k; l++) {
for (int m=0; m<n; m++) {
for (int o=0; o<=m; o++) {
apt[l][m] = apt[l][m] + apt[l-1][o];
}
}
}
System.out.println(apt[k][n-1]);
}
}
}'백준 문제풀이 > 기본수학1' 카테고리의 다른 글
| 10757. 큰 수 A+B (자바, Java) (2) | 2022.09.19 |
|---|---|
| 2839. 설탕 배달 (자바, Java) (1) | 2022.09.19 |
| 10250. ACM 호텔 (자바, Java) (0) | 2022.09.18 |
| 2869. 달팽이는 올라가고 싶다. (자바, Java) (0) | 2022.09.18 |
| 1193. 분수찾기 (자바, Java) (0) | 2022.09.18 |