728x90
반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring> // memset 헤더
using namespace std;
// [백준 2747 c++ O] 피보나치 수
// 문제:
// 접근: 피보나치 -> dp
// 시간복잡도: O(n) = 45
// 풀이:
#define MAX 92
int n;
int dp[MAX];
int main() {
ios::sync_with_stdio(false); // 계산시간 단축 // cin,scanf 같이 쓰면 오류
cin.tie(nullptr); cout.tie(nullptr);// 입출력 시간 단축 // 이것을 쓰면 scanf,printf섞어 쓰면 안됨
cin >> n;
dp[1] = 0;
dp[2] = 1;
for (int i = 3; i <= n + 1; i++) {
dp[i] = dp[i - 1] + dp[i - 2];
}
cout << dp[n + 1] << '\n';
return 0;
}
|
cs |
반응형
'Algorithm_BOJ(백준) > 동적프로그래밍(DP)' 카테고리의 다른 글
[백준 1890 c++ V] 점프 (0) | 2021.09.27 |
---|---|
[백준 11726 c++ VOO] 2×n 타일링 (0) | 2021.08.19 |
[백준 2748 c++ O] 피보나치 수 2 (0) | 2021.08.18 |
[백준 1463 c++ VOO] 1로 만들기 (0) | 2021.08.16 |
[백준 1495 c++ V] 기타리스트 (0) | 2021.08.11 |