문제
https://www.acmicpc.net/problem/2775
2775번: 부녀회장이 될테야
첫 번째 줄에 Test case의 수 T가 주어진다. 그리고 각각의 케이스마다 입력으로 첫 번째 줄에 정수 k, 두 번째 줄에 정수 n이 주어진다
www.acmicpc.net
주안점
배열을 사용하지 않는다. 배열 사용의 단점 (공간 복잡도의 증가)
구조
재귀적 용법으로 문제에 나온 조건을 이용
코드
#include<bits/stdc++.h>
using namespace std;
int t,k,n;
int go(int floor, int door) {
if(door == 1) return 1;
if(floor == 0) return door;
return go(floor-1, door)+go(floor, door-1);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>t;
for(int i=0; i<t; i++){
cin>>k>>n;
cout<<go(k,n)<<"\n";
}
}
'알고리즘 > 백준' 카테고리의 다른 글
[백준] 14716번 : 현수막 (0) | 2021.12.15 |
---|---|
[백준] 2292번 : 벌집 (0) | 2021.12.01 |
[백준] 2636번 : 치즈 (0) | 2021.11.09 |
[백준] 회의실 배정 (0) | 2021.11.04 |
[백준] 14501번 : 퇴사 (0) | 2021.10.27 |