您的位置:首页 > 其它

Beans

2015-10-19 10:31 183 查看
Description

Bean-eating is an interesting game, everyone owns an M*N matrix, which is filled with different qualities beans. Meantime, there is only one bean in any 1*1 grid. Now you want to eat the beans and collect the qualities, but everyone must obey by the following rules: if you eat the bean at the coordinate(x, y), you can’t eat the beans anyway at the coordinates listed (if exiting): (x, y-1), (x, y+1), and the both rows whose abscissas are x-1 and x+1.


#include <iostream>
using namespace std;
#define M 200005

int a[M], b[M];

int main()
{
int m, n, i, j;
while (~scanf ("%d%d", &m, &n))
{
for (i = 1; i <= m; i++)
{
for (j = 1; j <= n; j++)
scanf ("%d", b+j);
for (j = 2; j <= n; j++)
b[j] = max (b[j-2]+b[j], b[j-1]);
a[i] = b
;
}
for (i = 2; i <= m; i++)
a[i] = max (a[i]+a[i-2], a[i-1]);
printf ("%d\n", a[m]);
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: