-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDinamic Backtraking.cpp
98 lines (87 loc) · 1.5 KB
/
Dinamic Backtraking.cpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int mat[102][102];
int sol = -99999, n, m;
int d(int i,int j)
{
//cout<< i<<" "<< j<<" "<< "\n";
//system("PAUSE");
if(i == 1){
return mat[1][j];
}
else{
int max2 = d(i - 1,j), x;
if(j > 1){
x = d(i - 1, j - 1);
if (x > max2)
max2 = x;
}
if(j < m){
x = d(i - 1, j + 1);
if (x > max2)
max2 = x;
}
return max2 + mat[i][j];
}
}
int F[50];
bool calc[50];
int fib(int n)
{
if (calc[n])
return F[n];
if(n < 2)
F[n] = n;
else
F[n] = fib(n - 1) + fib(n - 2);
calc[n] = true;
return F[n];
}
int M[50];
bool cond[50];
int fac(int n)
{
if(!cond[n])
{
M[n] = n * fac(n - 1);
cond[n] = true;
}
return M[n];
}
int C(int n){
if (n < 2)
return 1;
int s = 0;
for (int i = 0 ; i <= n ; i++)
s += C(i) * C(n - i);
return s;
}
int main()
{
for (int i = 0 ; i < 6 ; i++)
cout << C(i) << ' ';
M[0] = 1;
cond[0] = true;
cout<< fac(5);
/*
cin>> n>>m;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
cin>> mat[i][j];
for(int i = 1;i <= m;i++){
int x = d( n, i );
if( x > sol )
sol = x;
cout<< sol<<endl;
}
printf("%d\n",sol);*/
return 0;
}
/*
3 3
100 100 1
-100 -100 100
-100 -100 10
*/