(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)点时的最大值然后转移显然是 ...
随机推荐
- Kooboo中怎么新增一个关联的Details 动态页面。
Kooboo中怎么新增一个关联的Details 动态页面. 有几个要点: 1. Sub Page的Parent Page 必须是英文书写.如果是中文会出现找不到页面 500错误 2. 要在Page M ...
- sql server 分布式事务
使用分布式事务刚好可以解决集群同时更新多台SQL SERVER数据库,要么全部成功,要么全部回滚的需要. 原来微软早考虑到此方面的问题了. 下面背书,贴出微软官网上面的帮助文档: 分布式事务跨越两个或 ...
- js 类似发微博或者微信朋友圈的时间显示 刚刚 几天前
群里的一个小伙伴(NightEagle)写的,共享出来了,我就做个记录. function getDateDiff(dateStr) { var publishTime = getDateTimeSt ...
- Android模拟器如何加载本机地址及访问本机服务器
首先获取本机ip地址: 在cmd 命令窗口中输入 ipconfig 查看本地电脑ip地址如下: 获取服务器上的Json数据,并返回结果,部分代码如下: 注:StreamUtils是自定义的一个工具类, ...
- C#- WinForm获取 当前执行程序路径的几种方法
1.获取和设置当前目录的完全限定路径.string str = System.Environment.CurrentDirectory;Result: C:xxxxxx 2.获取启动了应用程序的可执行 ...
- 删除已分配IP的静态IP地址池
如果静态IP地址池已经分配了IP,则无法直接将其静态IP地址池删除,会提示出错:“已经有IP被分配,需要先将其回收,再删除” 如下: 查看IP地址池: Get-SCStaticIPAddressPoo ...
- linux下启动某个进程
在关闭窗口的情况下,能够在后台继续运行,如 启动命令 node /home/node_modules/pixel-ping/lib/pixel-ping.js /home/node_modules/p ...
- vmtouch - the Virtual Memory Toucher
https://hoytech.com/vmtouch/ [root@localhost ~]# git clone git://github.com/hoytech/vmtouch.git 正克隆到 ...
- Volley完全解析
从前在学校用的最多的网络请求框架就是AsyncHttpClient,用久了发现这样一个问题,就是代码复用太难,基本上做不到,所以有一段时间又回归了HttpURLConnection和HttpClien ...
- Objective-C语法快速参考(C# 和 Objective-C 语法的比较)
大部分有一点其他平台开发基础的初学者看到XCode ,第一感想是磨拳擦掌,看到 Interface Builder 之后,第一感想是跃跃欲试,而看到Objective-C 的语法,第一感想就变成就望 ...