-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path24416.cpp
More file actions
56 lines (42 loc) · 792 Bytes
/
Copy path24416.cpp
File metadata and controls
56 lines (42 loc) · 792 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// [BOJ] 단계별로 풀어보기 > 16. 동적 계획법 1
// 24416. 알고리즘 수업 - 피보나치 수 1
// 2022.08.26
/* Sample input & output data
5
5 3
30
832040 28
*/
#include <iostream>
#include <vector>
using namespace std;
#define endl '\n'
// Recursion
int fib(int n, int* p1)
{
if (n == 1 || n == 2)
{
(*p1)++;
return 1;
}
else return fib(n - 1, p1) + fib(n - 2, p1);
}
// Dynamic Programming …… originally, but?
int fibonacci(int n, int* p2)
{
// do not need to get the fibonacci number
*p2 = n - 2;
return 1;
}
int main()
{
int n;
cin >> n;
int cnt1 = 0, cnt2 = 0;
int* p1 = &cnt1;
int* p2 = &cnt2;
fib(n, p1);
fibonacci(n, p2);
cout << cnt1 << " " << cnt2 << endl;
return 0;
}