-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamic.cs
More file actions
56 lines (44 loc) · 1.07 KB
/
Dynamic.cs
File metadata and controls
56 lines (44 loc) · 1.07 KB
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
using System;
namespace DynamicAlgo
{
class Dynamics
{
static int MAX = 100;
static int NIL = -1;
static int[] lookup = new int[MAX];
/* Function to initialize NIL
values in lookup table */
static void initialize()
{
for (int i = 0; i < MAX; i++)
lookup[i] = NIL;
}
public static int Memorizarion(int n)
{
if (lookup[n] == NIL) b
{
if (n <= 1)
lookup[n] = n;
else
{
lookup[n] = Memorizarion(n - 1) + Memorizarion(n - 2);
}
}
return lookup[n];
}
static int fib(int n)
{
int []f = new int[n + 1];
f[0] = 0;
f[1] = 1;
for (int i = 2; i <= n; i++)
f[i] = f[i - 1] + f[i - 2];
return f[n];
}
public static void MainC(string[] args)
{
initialize();
Console.Write(Memorizarion(9));
}
}
}