-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path51867.cpp
67 lines (56 loc) · 1.21 KB
/
51867.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
#include <bits/stdc++.h>
using namespace std;
int arr[1010][1010];
int brr[1010][1010];
int main()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf("%d",&arr[i][j]);
}
}
for(int j=m;j>=1;j--)
{
if(arr[n][j])
{
brr[n][j]=arr[n][j]+brr[n][j+1];
}
}
int turn=0;
for(int i=n-2;i>=1;i-=2)
{
for(int j=m;j>=1;j--)
{
if(arr[i][j])
{
if(turn%2==0)/// left
{
if(max(brr[i][j+1],brr[i+2][j+1])>0)
brr[i][j]=arr[i][j]+max(brr[i][j+1],brr[i+2][j+1]);
}
else
{
if(max(brr[i][j+1],brr[i+2][j-1])>0)
brr[i][j]=arr[i][j]+max(brr[i][j+1],brr[i+2][j-1]);
}
}
}
turn++;
}
/*for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
cout<<brr[i][j]<<"\t";
cout<<endl;
}*/
int maxi=-1;
//for(int i=1;i<=n;i+=2)
for(int j=1;j<=m;j++)
maxi=max(maxi,brr[1][j]);
cout<<maxi<<endl;
return 0;
}