F - Monkey Banana Problem
F - Monkey Banana Problem
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Description
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 (≤ 50), denoting the number of test cases.
Every case starts with an integer N (1 ≤ N ≤ 100). It denotes that, there will be 2*N - 1 rows. The ith (1 ≤ i ≤ N) line of next N lines contains exactly i numbers. Then there will be N - 1 lines. The jth (1 ≤ j < N) line contains N - j integers. Each number is greater than zero and less than 215.
Output
For each case, print the case number and maximum number of bananas eaten by the monkey.
Sample Input
2
4
7
6 4
2 5 10
9 8 12 2
2 12 7
8 2
10
2
1
2 3
1
Sample Output
Case 1: 63
Case 2: 5
//题意第一行是 T 组测试数据,第二行 n 然后是 2*n-1 行的数据
从最上面那里出发,只能选做下走或者右下走,走到最下面那个位置,求路径上最大的和。
//很简单的 dp 注意一些特殊的情况就行
//72ms
#include <stdio.h>
#include <string.h> int num[][];
int dp[][]; int max(int a ,int b)
{return a>b?a:b;} int main()
{
int T,Case=;
int i,j;
scanf("%d",&T);
while (T--)
{
int n;
scanf("%d",&n);
for (i=;i<=*n-;i++)
{
if (i<=n)
for (j=;j<=i;j++)
scanf("%d",&num[i][j]);
else
for (j=;j<=*n-i;j++)
scanf("%d",&num[i][j]);
} memset(dp,,sizeof(dp));
for (i=*n-;i>=;i--)
{
if (i<n)
{
for (j=;j<=i;j++)
dp[i][j]=max(dp[i+][j],dp[i+][j+])+num[i][j];
}
else
{
for (j=;j<=*n-i;j++)
{
if (j==)
dp[i][j]=dp[i+][j]+num[i+][j];
if (j!=&&j==*n-i)
dp[i][j]=dp[i+][j-]+num[i][j]; dp[i][j]=max(dp[i+][j-],dp[i+][j])+num[i][j];
}
}
}
printf("Case %d: ",++Case);
printf("%d\n",dp[][]);
}
return ;
}
F - Monkey Banana Problem的更多相关文章
- 2016huasacm暑假集训训练五 F - Monkey Banana Problem
题目链接:http://acm.hust.edu.cn/vjudge/contest/126708#problem/F 题意:求至上而下一条路径的所经过的值得和最大值,这题比赛时就出了 但当时看不懂题 ...
- (LightOJ 1004) Monkey Banana Problem 简单dp
You are in the world of mathematics to solve the great "Monkey Banana Problem". It states ...
- Monkey Banana Problem LightOJ - 1004
Monkey Banana Problem LightOJ - 1004 错误记录: 1.数组开小2.每组数据数组没有清空 #include<cstdio> #include<cst ...
- Light oj-1004 - Monkey Banana Problem,数字三角形的变形版~
100 ...
- Lightoj 1004 - Monkey Banana Problem
题目链接:http://acm.hust.edu.cn/vjudge/contest/121396#problem/F http://lightoj.com/volume_showproblem.ph ...
- [LightOJ1004]Monkey Banana Problem(dp)
题目链接:http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1004 题意:数塔的变形,上面一个下面一个,看清楚 ...
- Light OJ 1004 - Monkey Banana Problem(DP)
题目大意: 给你一菱形的数字阵,问从最上面走到最下面所能获得的最大值是多少? #include<cstdio> #include<cstring> #include<io ...
- Educational Codeforces Round 40 F. Runner's Problem
Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...
- Day9 - F - Monkey and Banana HDU - 1069
一组研究人员正在设计一项实验,以测试猴子的智商.他们将挂香蕉在建筑物的屋顶,同时,提供一些砖块给这些猴子.如果猴子足够聪明,它应当能够通过合理的放置一些砖块建立一个塔,并爬上去吃他们最喜欢的香蕉. ...
随机推荐
- iptables利用connlimit模块限制同一IP连接数
connlimit功能: connlimit模块允许你限制每个客户端IP的并发连接数,即每个IP同时连接到一个服务器个数. connlimit模块主要可以限制内网用户的网络使用,对服务器而言则可以限制 ...
- 走进C++程序世界-----operator new delete 重载
在C++ 的世界里,new 和delete 是keyword.而在C的世界里相相应的malloc和free是函数,关键C++的new和delete分析,详见前面的章节.这里就不在过多的介绍了.链接. ...
- 把e.printStackTrace的堆栈信息打印在log.error()中
不要这样写: log.error(e);这样只是简单的记录下错误的类型,不能精确出错误出错在哪行 要写成:log.error(e.toString(),e);
- 解决ie7下overflow:hidden失效问题
但父亲元素下面的子节点或者孙子节点有position:relative:或者absolute时,父亲即使设置了overflow:hidden:依然会溢出 解决方法可以: 在父亲元素上加上*positi ...
- 嵌套矩形——DAG上的动态规划
有向无环图(DAG,Directed Acyclic Graph)上的动态规划是学习动态规划的基础.非常多问题都能够转化为DAG上的最长路.最短路或路径计数问题. 题目描写叙述: 有n个矩形,每一个矩 ...
- Eclipse 使用 SVN 插件后改动用户方法汇总
判定 SVN 插件是哪个 JavaH 的处理方法 SVNKit 的处理方法 工具自带改动功能 删除缓存的秘钥文件 其他发表地点 判定 SVN 插件是哪个 常见的 Eclipse SVN 插件我知道的一 ...
- [1-6] 把时间当做朋友(李笑来)Chapter 6 【更多思考】 摘录
记住,你不可能百分之百地有效率,至少不可能总是百分之百地有效率. 他们的效率很差.根源在于,他们其实只做简单的事情,而回避那些有难度的工作. 好像丢钱包的人都不是“故意”丢的一样,办事拖拉的人大多并非 ...
- eclipse上的git命令使用浅析,搭建Maven项目
eclipse上的git命令使用浅析 2016-03-31 14:44 关于eclipse上git的安装和建立代码仓库的文章比较多,但作为一个初识git的人更希望了解每个命令的作用. 当项目连接到 ...
- nightwatchJS ---element用法
.element() Search for an element on the page, starting from the document root. The located element w ...
- CSS3:选择器
CSS选择器的作用是找出某类元素,以便我们使用style元素或者外部样式表对这类元素设置样式. 基本选择器 选择器 含义 演示样例 描写叙述 * 选择全部元素 * { border: thin bla ...