-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfib.cpp
More file actions
45 lines (38 loc) · 857 Bytes
/
fib.cpp
File metadata and controls
45 lines (38 loc) · 857 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
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <vector>
#include "integerFunctions.hpp"
using namespace std;
long long fib(long long n,vector<long long>& keys)
{
if (keys[n-1] != -1) return keys[n-1];
if(n<3) return 1;
else keys[n-1] = fib(n-1,keys)+fib(n-2,keys);
return keys[n-1];
}
vector<long long> fibDP(long long n)
{
vector<long long> keys(n,-1);
fib(n,keys);
return keys;
}
int main(int argc, char** argv)
{
long long upper = atoi(argv[1]);
/*vector<long long> keys = fibDP(upper);
for(long long i = 0; i < upper; i++)
{
cout << "fib("<<i+1<<")="<<keys[i]<<endl;
}*/
vector<long long> stuff(upper,-1);
stuff[1]=1;
for(long long i = 2; i < upper; i++)
{
stuff[i]=stuff[i-1]+stuff[i-2];
}
for(long long i = 1; i < upper; i++)
{
cout << "fib("<<i<<")="<<stuff[i]<<endl;
}
}