-
Notifications
You must be signed in to change notification settings - Fork 0
/
MISERMAN.cpp
53 lines (53 loc) · 1.31 KB
/
MISERMAN.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
#include <iostream>
using namespace std;
int main()
{
int n, m,a[102][102],i,j,max;
cin>>n>>m;
for (i=0;i<n;i++)
for (j=0;j<m;j++)
cin>>a[i][j];
for (i=n-2;i>=0;i--)
{
for (j=0;j<m;j++)
{
if (j==0)
{
if (a[i+1][j]>a[i+1][j+1])
a[i][j]+=a[i+1][j+1];
else
a[i][j]+=a[i+1][j];
}
else if (j<n-1)
{
if (a[i+1][j]>a[i+1][j+1])
{
if (a[i+1][j+1]>a[i+1][j-1])
a[i][j]+=a[i+1][j-1];
else
a[i][j]+=a[i+1][j+1];
}
else
{
if (a[i+1][j-1]>a[i+1][j])
a[i][j]+=a[i+1][j];
else
a[i][j]+=a[i+1][j-1];
}
}
else
{
if (a[i+1][j-1]<a[i+1][j])
a[i][j]+=a[i+1][j-1];
else
a[i][j]+=a[i+1][j];
}
}
}
max=a[0][0];
for (i=1;i<m;i++)
if (max>a[0][i])
max=a[0][i];
cout<<max<<endl;
return 0;
}