nyoj 吃土豆 234 (双层DP)
来源:互联网 发布:淘宝昵称 编辑:程序博客网 时间:2024/04/30 05:10
吃土豆
时间限制:1000 ms | 内存限制:65535 KB
难度:4
- 描述
- 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.
Now, how much qualities can you eat and then get ?- 输入
- There are a few cases. In each case, there are two integer M (row number) and N (column number). The next M lines each contain N integers, representing the qualities of the beans. We can make sure that the quality of bean isn't beyond 1000, and 1<=M,N<=500.
- 输出
- For each case, you just output the MAX qualities you can eat and then get.
- 样例输入
4 611 0 7 5 13 978 4 81 6 22 41 40 9 34 16 1011 22 0 33 39 6
- 样例输出
242
//题意://给你n行m列的矩阵,矩阵上的数代表此处有多少豆子,问最多能吃多少豆子//但吃豆子有一定的规则。//规则::如果你吃了某处的豆子,那么你不能再吃它左边和右边的两处的豆子,并且不能吃它上下两行的豆子//思路://双层DP,先求出每行的最大值,再求全部的最大值。
#include<stdio.h>#include<string.h>int max(int x,int y){return x>y?x:y;}int dp[510];int a[510][510];int main(){int n,m,i,j,w;while(scanf("%d%d",&n,&m)!=EOF){memset(dp,0,sizeof(dp));memset(a,0,sizeof(a));for(i=3;i<n+3;i++){for(j=3;j<m+3;j++){scanf("%d",&w);a[i][j]=max(a[i][j-2],a[i][j-3])+w;}}for(i=3;i<n+3;i++)dp[i]=max(dp[i-2],dp[i-3])+max(a[i][m+1],a[i][m+2]);printf("%d\n",max(dp[n+1],dp[n+2]));}return 0;}
0 0
- nyoj 吃土豆 234 (双层DP)
- NYOJ234-吃土豆(双层DP)
- NYOJ-234-DP(吃土豆)
- nyoj 234 吃土豆
- Nyoj 234 吃土豆
- nyoj 234 吃土豆
- NYOJ234吃土豆(双层动态规划)
- nyoj-234-吃土豆(动态规划)
- NYOJ 题目234 吃土豆
- nyoj-动态规划-234-吃土豆-201308131021
- 双层动态规划_吃土豆问题
- NYOJ 吃土豆(动态规划)
- hdu-Beans(动态规划,nyoj-234-吃土豆)
- 题目234 吃土豆
- 吃土豆
- 吃土豆
- 吃土豆
- 吃土豆
- centos7安装有道词典(不能发音和取词)
- MySQL-2 :MVCC及实现介绍
- 机器学习实战(三)
- call_function_single_interrupt stack checking
- SQL 左外连接,右外连接,全连接,内连接
- nyoj 吃土豆 234 (双层DP)
- 做程序猿8个月的感受(二)~
- vs2013下如何调试main带参数的程序
- 杭电1251
- 杭电1075 What Are You Talking About
- Volley框架之使用GET取得Cookie
- android studio gradle更新错误
- normalize()函数的使用方法
- javaScript-运算符、表达式和控制语句