Nyoj 234 吃土豆

来源:互联网 发布:linux设置pxe启动 编辑:程序博客网 时间:2024/04/30 06:30
/**#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;}

0 0
原创粉丝点击