[BOJ]4779 칸토어 집합

강동현·2023년 12월 23일
0

코딩테스트

목록 보기
40/111
  • 재귀 sol
  1. baseconditionbase condition을 정의한다.(문제에서 case 0이 주어져서 설정하기 쉬움)
  2. f(basecondition)>f(basecondition+1)f(base condition) -> f(base condition+1)의 관계에서 f(n)>f(n+1)f(n) -> f(n+1)의 점화식을 발견한다.
  3. 점화식에 따른 함수를 정의한다.
#include <bits/stdc++.h>
using namespace std;
int N;
void cantour(int n){
    //1. base condition 정의
    if(n == 0) {
        cout << '-';
        return;
    }
    //2. f(base condition) -> f(base condition + 1)의 관계에서 규칙(점화식) 찾기
    cantour(n-1);
    for(int i = 0; i < pow(3, (n - 1)); ++i) cout << ' ';
    cantour(n-1);
}
int main(){
    while(cin >> N){
        cantour(N);
        cout << '\n';
    }
    return 0;
}
profile
GAME DESIGN & CLIENT PROGRAMMING

0개의 댓글