문제 링크입니다: www.acmicpc.net/problem/10870
10870번: 피보나치 수 5
피보나치 수는 0과 1로 시작한다. 0번째 피보나치 수는 0이고, 1번째 피보나치 수는 1이다. 그 다음 2번째 부터는 바로 앞 두 피보나치 수의 합이 된다. 이를 식으로 써보면 Fn = Fn-1 + Fn-2 (n ≥ 2)가
www.acmicpc.net
간단한 dp 문제였습니다.
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 <iostream> | |
using namespace std; | |
const int MAX = 20 + 1; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int n; | |
cin >> n; | |
long long fibonacci[MAX]; | |
fibonacci[0] = 0; | |
fibonacci[1] = 1; | |
for (int i = 2; i <= n; i++) | |
{ | |
fibonacci[i] = fibonacci[i - 1] + fibonacci[i - 2]; | |
} | |
cout << fibonacci[n] << "\n"; | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 21598번 SciComLove (0) | 2021.04.25 |
---|---|
백준 11444번 피보나치 수 6 (0) | 2021.04.25 |
백준 2742번 기찍 N (0) | 2021.04.25 |
백준 2741번 N 찍기 (0) | 2021.04.25 |
백준 2739번 구구단 (0) | 2021.04.25 |