1
#include
<iostream>
2
#include
<memory.h>
3
using
namespace std;
4
int tem[
501][
501];
5
int main()
6 {
7
int h,r;
8 cin>>h>>r;
9
for(
int i=
0;i<h;i++)
10
for(
int j=
0;j<r;j++)
11 cin>>tem[i][j];
12
for(
int i=
1;i<h;i++)
13
for(
int j=
0;j<r;j++)
14 {
15
int ans=
0;
16
if(j-
1>-
1&&tem[i-
1][j-
1]>ans)
17 ans=tem[i-
1][j-
1];
18
if(tem[i-
1][j]>ans)
19 ans=tem[i-
1][j];
20
if(j+
1<r&&tem[i-
1][j+
1]>ans)
21 ans=tem[i-
1][j+
1];
22 tem[i][j]+=ans;
23 }
24
int ans=
0;
25
for(
int i=
0;i<r;i++)
26 {
27
if(ans<tem[h-
1][i])
28 ans=tem[h-
1][i];
29 }
30 cout<<ans<<endl;
31 }
转载于:https://www.cnblogs.com/congzc/archive/2011/07/12/2329939.html