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; }
相关文章推荐
- NYOJ 234 吃土豆
- hdu-Beans(动态规划,nyoj-234-吃土豆)
- nyoj 234 吃土豆
- nyoj234 吃土豆 01背包
- NYOJ 234 吃土豆(基础dp)
- nyoj-动态规划-234-吃土豆-201308131021
- NYOJ 题目234 吃土豆
- NYOJ-234 吃土豆
- NYOJ_234_吃土豆
- nyoj 234 吃土豆
- NYOJ-234-DP(吃土豆)
- NYOJ 234 吃土豆
- nyoj-234-吃土豆(动态规划)
- nyoj 吃土豆 234 (双层DP)
- 吃土豆_nyoj_234(动态规划).java
- NYOJ234吃土豆(双层动态规划)
- NYOJ234吃土豆
- nyoj 234 吃土豆
- NYOJ234-吃土豆(双层DP)
- NYOJ 吃土豆(动态规划)