(LightOJ 1004) Monkey Banana Problem 简单dp
You are in the world of mathematics to solve the great "Monkey Banana Problem". It states that, a monkey enters into a diamond shaped two dimensional array and can jump in any of the adjacent cells down from its current position (see figure). While moving from one cell to another, the monkey eats all the bananas kept in that cell. The monkey enters into the array from the upper part and goes out through the lower part. Find the maximum number of bananas the monkey can eat. Input
Input starts with an integer T (≤ ), denoting the number of test cases. Every case starts with an integer N ( ≤ N ≤ ). It denotes that, there will be *N - rows. The ith ( ≤ i ≤ N) line of next N lines contains exactly i numbers. Then there will be N - lines. The jth ( ≤ j < N) line contains N - j integers. Each number is greater than zero and less than . Output
For each case, print the case number and maximum number of bananas eaten by the monkey. Sample Input
Output for Sample Input Case :
Case :
题意 从上到下,使和最大
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include <math.h>
#include<queue>
#define ll long long
#define INF 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof(a));
#define N 511
using namespace std;
int dp[N][N],a[N][N];
int main()
{
int t,n,con=;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
for(int j=; j<=i; j++)
scanf("%d",&a[i][j]);
}
for(int i=n+; i<*n; i++)
{
for(int j=; j<=*n-i; j++)
scanf("%d",&a[i][j]);
}
met(dp,);
dp[][]=a[][];
for(int i=; i<=n; i++)
{
for(int j=; j<=i; j++)
{
dp[i][j]=max(dp[i][j],dp[i-][j-]+a[i][j]);
dp[i][j]=max(dp[i][j],dp[i-][j]+a[i][j]);
}
}
for(int i=n+; i<*n; i++)
{
for(int j=; j<=*n-i; j++)
{
dp[i][j]=max(dp[i][j],dp[i-][j]+a[i][j]);
dp[i][j]=max(dp[i][j],dp[i-][j+]+a[i][j]);
}
}
printf("Case %d: %d\n",con++,dp[*n-][]);
}
return ;
}
(LightOJ 1004) Monkey Banana Problem 简单dp的更多相关文章
- Lightoj 1004 - Monkey Banana Problem
题目链接:http://acm.hust.edu.cn/vjudge/contest/121396#problem/F http://lightoj.com/volume_showproblem.ph ...
- Light OJ 1004 - Monkey Banana Problem(DP)
题目大意: 给你一菱形的数字阵,问从最上面走到最下面所能获得的最大值是多少? #include<cstdio> #include<cstring> #include<io ...
- [LightOJ1004]Monkey Banana Problem(dp)
题目链接:http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1004 题意:数塔的变形,上面一个下面一个,看清楚 ...
- Light oj-1004 - Monkey Banana Problem,数字三角形的变形版~
100 ...
- Monkey Banana Problem LightOJ - 1004
Monkey Banana Problem LightOJ - 1004 错误记录: 1.数组开小2.每组数据数组没有清空 #include<cstdio> #include<cst ...
- F - Monkey Banana Problem
F - Monkey Banana Problem Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & ...
- 2016huasacm暑假集训训练五 F - Monkey Banana Problem
题目链接:http://acm.hust.edu.cn/vjudge/contest/126708#problem/F 题意:求至上而下一条路径的所经过的值得和最大值,这题比赛时就出了 但当时看不懂题 ...
- lightoj 1004 dp:数字三角形
题目链接:http://lightoj.com/volume_showproblem.php?problem=1004 #include <cstdio> #include <cst ...
- lightoj 1036 - A Refining Company(简单dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1036 题解:设dp[i][j]表示处理到(i,j)点时的最大值然后转移显然是 ...
随机推荐
- allegro
ALLEGRO5的渲染部分低层使用了opengl或d3d加速.
- win7下wubi安装Ubuntu,重装win7后找回Ubuntu启动项
怀念一下我的win7,使用了将近5年,最近终于慢慢处于崩溃且无法修复的状态. 还是重新安装了. 原本是win7下使用wubi安装Ubuntu.重装win7后,肯定没有了Ubuntu的启动项. 具体恢复 ...
- javascript函数库
//构造缓存函数 var memoizer = function (memo, fundamental) { var shell = function (n) { var result = memo[ ...
- 多组radio传值注意事项
多组radio传值,每组的radio name必须不同,否则所有的radio将被视为一组,传值时只会传其中一组的值到后台,如果这时你用数组接收从前台传过来的值并使用,就会报数组越界异常
- [置顶] 程序员必知(三):一分钟知道URI编码(encodeURI)
因为浏览器会用一些特殊的字符作为特定的意义,所以在要传输的内容上如果有这些特殊的字符的话,就需要对其进行转义才能正确传输,如以下字符为发送时候的关键字,即特殊字符 ;/?:@&=+$,# 所以 ...
- 自己动手Jquery插件
最近Web应用程序中越来越多地用到了JQuery等Web前端技术.这些技术框架有效地改善了用户的操作体验,同时也提高了开发人员构造丰富客户 端UI的效率.JQuery本身提供了丰富的操作,但是,有时候 ...
- 微软的.NET示例代码放在Github上了
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:微软的.NET示例代码放在Github上了.
- 【面试虐菜】—— Oracle知识整理《收获,不止Oracle》
普通堆表不足之处: 表更新有日志开销 表删除有瑕疵 表记录太大检索较慢 索引回表读开销很大 有序插入难有序读出 DELETE产生的undo最多,redo也最 ...
- Junit中常用的注解说明
Java注解((Annotation)的使用方法是@注解名 ,能通过简单的词语来实现一些功能.在junit中常用的注解有@Test.@Ignore.@BeforeClass.@AfterClass.@ ...
- Windows系统下的adb 配置
1.将附件中的adb_tools.rar文件下载到电脑上,并解压.(注意:其路径尽量避免带有中文字符) 2.右键点击“计算机”->“属性”->“高级系统设置”->“高级”->“ ...