您的位置:首页 > 其它

Nyoj 234 吃土豆

2014-03-21 15:31 274 查看
/**
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

const int MAXN = 510;

int MAX(int a, int b)
{
return a > b ? a : b;
}

int main()
{
int row, col;
int Graph[MAXN][MAXN];
int dp[MAXN];

int i, j;

while (~scanf("%d %d", &row, &col))
{
memset(Graph, 0, sizeof(Graph));
memset(dp, 0, sizeof(dp));

for (i = 3; i < row+3; ++i)
{
for (j = 3; j < col+3; ++j)
{
scanf("%d", &Graph[i][j]);
Graph[i][j] += MAX(Graph[i][j-2], Graph[i][j-3]) ;
}
}

for (i = 3; i < row + 3; ++i)
{
dp[i] += MAX(dp[i-2], dp[i-3]) + MAX(Graph[i][col+1], Graph[i][col+2]);
}
cout<<dp[row+2]<<endl;
}
return 0;
}
*/

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

const int MAXN  = 510;

int MAX(int a, int b)
{
return a > b ? a : b;
}

int main()
{
int row, col;
int Graph[MAXN][MAXN];
int dp[MAXN];
int i, j;

while (~scanf("%d %d", &row, &col))
{
memset(Graph, 0, sizeof(Graph));
memset(dp, 0, sizeof(dp));

for (i = 3; i < row+3; ++i)
{
for (j = 3; j < col+3; ++j)
{
scanf("%d", &Graph[i][j]);
Graph[i][j] += MAX(Graph[i][j-2], Graph[i][j-3]);//在第i行从第0个位置到第j个位置可以吃到最多的土豆,跟第i行j-2,j-3两列有关
}
dp[i] = MAX(dp[i-2], dp[i-3]) + MAX(Graph[i][col+1], Graph[i][col+2]);
}

printf("%d\n",dp[row+2]);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: