文章
25
粉丝
364
获赞
8
访问
220.6k
/*
* Description: 淘金 (http://noobdream.com/DreamJudge/Issue/page/1676/)
* Author: 鱼翔浅底
* Date: 2021-02-22 16:52:35
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
#define MAX 200
int MaxValue(int v[], int k)
{
int dp[MAX];
dp[0] = v[0];
if (k >= 2)
{
dp[1] = (v[0] > v[1]) ? v[0] : v[1];
}
for (int i = 2; i < k; i++)
{
dp[i] = (dp[i - 1] > dp[i - 2] + v[i]) ? dp[i - 1] : dp[i - 2] + v[i];
}
return dp[k - 1];
}
int main()
{
int n, m;
int row[MAX], column[MAX];
while (~scanf("%d%d", &n, &m))
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
scanf("%d", row + j);
}
column[i]=MaxValue(row,m);//算出每行的最大值
}
printf("%d\n",MaxValue(column,n));//算出总的最大值
}
...
登录后发布评论
暂无评论,来抢沙发