k-1층의 1~b호 까지의 사람들이 k층 b호에 살아야 된다.
0층 i호에는 i명이 산다.
배열이
1 2 3 4 5
1 3 6 10 15
이런식으로 만들어진다.
위에서 부터 0층 1층 으로 계산했을때
d[i][j] = d[i-1][j] + d[i][j-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
#include <cstdio> | |
/** | |
* https://www.acmicpc.net/problem/2775 | |
* BOJ 백준온라인져지 2775 부녀회장이 될테야 풀이 | |
*/ | |
#define MAX 15 | |
int main(){ | |
int T,k,n; | |
scanf("%d", &T); | |
int d[MAX][MAX] = {}; | |
for(int i = 1; i<MAX; i++){ | |
d[0][i] = i; | |
d[i][1] = 1; | |
} | |
for(int i = 1; i<MAX; i++){ | |
for(int j = 2; j<MAX; j++){ | |
d[i][j] = d[i][j-1] + d[i-1][j]; | |
} | |
} | |
while(T--){ | |
scanf("%d%d",&k,&n); | |
printf("%d\n",d[k][n]); | |
} | |
return 0; | |
} |
'IT > 알고리즘' 카테고리의 다른 글
BOJ 백준온라인져지 6064 카잉 달력 풀이 (0) | 2017.11.14 |
---|---|
BOJ 백준온라인져지 1475 방 번호 풀이 (0) | 2017.11.13 |
BOJ 백준온라인져지 10250 ACM 호텔 풀이 (0) | 2017.11.12 |
BOJ 백준 1011 Fly me to the Alpha Centauri 풀이 Raw (0) | 2017.11.12 |
BOJ 2188 풀이 (이분매칭) (0) | 2017.11.08 |