-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDAY3.cpp
More file actions
58 lines (54 loc) · 962 Bytes
/
DAY3.cpp
File metadata and controls
58 lines (54 loc) · 962 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
57
58
//MEMORIZATION
#include<iostream>
#include<limits.h>
using namespace std;
int memory[1000];
int memoryFibonacci(int n)
{
if(n<=1)
{
memory[n]=n;
return n;
}
else
{
if(memory[n-1] == -1)
{
memory[n-1] = memoryFibonacci(n-1);
}
if(memory[n-2] == -1)
{
memory[n-2] = memoryFibonacci(n-2);
}
memory[n] = memory[n-1] + memory[n-2];
return memory[n];
}
}
int main()
{
for(int i=0;i<1000;i++)
{
memory[i]= -1;
}
cout<<memoryFibonacci(10);
}
//TOWER OF HANOI
#include<iostream>
using namespace std;
void tower(int n,char a,char b,char c)
{
if(n>0)
{
tower(n-1,a,c,b);
cout<<"Move from "<<a<<" to "<<c<<endl;
tower(n-1,b,a,c);
}
else{
return ;
}
}
int main()
{
tower(12,'A','B','C');
return 0;
}