https://www.acmicpc.net/problem/10870
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
void CPP_INIT() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int fibo(int n) {
if (n == 0) return 0;
else if (n == 1 || n == 2) return 1;
else return fibo(n - 1) + fibo(n - 2);
}
int main(void) {
CPP_INIT();
int input;
cin >> input;
cout << fibo(input);
}
'알고리즘' 카테고리의 다른 글
C++ 알고리즘 - 백준 24060 알고리즘 수업 - 병합 정렬 1 (0) | 2025.01.17 |
---|---|
C++ 알고리즘 - 백준 25501 재귀의 귀재 (참조자 문자열) (0) | 2025.01.17 |
C++ 알고리즘 - 백준 11729 하노이 탑 이동순서 (재귀함수) (0) | 2025.01.17 |
C++ 알고리즘 - 백준 20920 영단어 암기는 괴로워 (맵, 벡터) (0) | 2025.01.17 |
C++ 알고리즘 - 백준 26069 붙임성 좋은 총총이 (0) | 2025.01.16 |