728x90
k층에 n호에는 몇명이 살아야하는지 출력을 해야합니다.
k층에 n호는 k-1층에 1~n호의 사람들의 합만큼 살아야합니다.
...
2층 1 4 10 20 ...
1층 1 3 6 10 ...
0층 1 2 3 4 ...
1호 2호 3호 4호
house[]에는 0층 1호~14호까지의 인원이 입력되어 있습니다. ex) 1, 2, 3, 4 .... 12, 13, 14
그리고 찾고자 하는 k층이 될때까지 house[]에는 그다음 층의 값들로 업데이트를 해주도록 하였습니다.
#include <iostream>
using namespace std;
int house[14];
void init() {
for (int i = 0; i < 14; ++i) {
house[i] = i + 1;
}
}
int main(int argc, char * argv[])
{
int cycle;
int k, n;
int result = 0;
int tmp = 0;
cin >> cycle;
for (int i = 0; i < cycle; ++i) {
cin >> k;
cin >> n;
init();
for (int j = 0; j < k; ++j) {
for (int h = 0; h < n; ++h) {
house[h] += tmp;
tmp = house[h];
}
result = tmp;
tmp = 0;
}
cout << result << endl;
}
return 0;
}
'알고리즘' 카테고리의 다른 글
[C++] 백준 2163번 초콜릿 자르기 (0) | 2019.03.06 |
---|---|
[C++] 백준 1475번 방 번호 (0) | 2019.03.05 |
[C++] 백준 2908번 상수 (0) | 2019.03.05 |
[C++] 백준 4673번 셀프 넘버 (0) | 2019.03.05 |
[C++] 백준 1110번 더하기 사이클 (0) | 2019.03.05 |