-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA32.js
More file actions
44 lines (36 loc) · 882 Bytes
/
A32.js
File metadata and controls
44 lines (36 loc) · 882 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
const n = 5;
let dp = [[7],[3,8],[8,1,0],[2,7,4,4],[4,5,2,6,5]];
//for(let i=1;i<n;i++){
/// dp.push(input[i].split(" ").map((v)=>+v));
//}
for(let i=1;i<n;i++){
for(let j=0; j<i+1;j++){
let up_left = 0;
let up = 0;
if(j!==0){
up_left = dp[i-1][j-1];
}
if(j!==i){
up = dp[i-1][j];
}
dp[i][j]= dp[i][j]+Math.max(up_left,up);
}
}
console.log(Math.max(...dp[n-1]));
//////////////////////////////////////////
//const n = 5;
dp = [[7],[3,8],[8,1,0],[2,7,4,4],[4,5,2,6,5]];
for(let i=1; i<n;i++){
for(let j=0; j<=i;j++){
let up_left = 0;
let up =0;
if(j!==0){
up_left = dp[i-1][j-1];
}
if(j!==i){
up = dp[i-1][j];
}
dp[i][j] = dp[i][j]+ Math.max(up_left,up);
}
}
console.log(Math.max(...dp[n-1]));