sicily/1563. GECKO
2011-07-12 12:50 Min·zc 阅读(171) 评论(0) 编辑 收藏 举报
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 }
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 }