forked from arv002-zz/spojcodes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BYTESM2 - Philosophers Stone.cpp
77 lines (62 loc) · 1.62 KB
/
BYTESM2 - Philosophers Stone.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
#include<bits/stdc++.h>
using namespace std;
long long Max(long long a, long long b, long c)
{
if(a<b)
{
if(b>c)
return b;
else
return c;
}
else
{
if(a>c)
return a;
else
return c;
}
}
int main()
{
long long T;
cin>>T;
while(T--)
{
long long h,w,i,j,k;
cin>>h>>w;
long long a[h][w];
for(i=0; i<h; i++)
for(j=0; j<w; j++)
cin>>a[i][j];
long long dp[h+1][w+1];
for(i=0; i<w; i++)
dp[0][i]=a[0][i];
//cout<<dp[0][i]<<"a ";}
for(i=0; i<h; i++)
for(j=0; j<w; j++)
{
if(j-1<0)
{dp[i+1][j]=max(dp[i][j]+(a[i+1][j+1]),
dp[i][j]+(a[i+1][j]) );
//cout<<a[i+1][j+1]<<"bhenchod"<<a[i+1][j]<<"madarchod"<<"\n";
//cout<<dp[i][j]<<" ";
}
else if(j+1>=w)
dp[i+1][j]=max((dp[i][j]+a[i+1][j-1]),
(dp[i][j]+a[i+1][j])
);
else
dp[i+1][j]= Max((dp[i][j]+a[i+1][j-1]),
(dp[i][j]+a[i+1][j+1]),
(dp[i][j]+a[i+1][j])
);
}
for(i=0;i<h;i++)
{
for(j=0;j<w;j++)
cout<<dp[i][j]<<" " ;
cout<<"\n";
}
}
}