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
一组研究人员正在设计一项实验,以测试猴子的智商.他们将挂香蕉在建筑物的屋顶,同时,提供一些砖块给这些猴子.如果猴子足够聪明,它应当能够通过合理的放置一些砖块建立一个塔,并爬上去吃他们最喜欢的香蕉. ...
随机推荐
- Snapdragon connect to android devices
怎么都连不上,连不上连不上... 用adb devices是列出来的,开发者选项也设置了, 后来查了下 把adb的路径拖到系统环境变量里就可以了.终于连上了,今天不用加班了...
- log4j教程 7、日志记录级别
org.apache.log4j.Level类提供以下级别,但也可以通过Level类的子类自定义级别. Level 描述 ALL 各级包括自定义级别 DEBUG 指定细粒度信息事件是最有用的应用程序调 ...
- ElasticSearch 监控单个节点详解
1.介绍 集群健康 就像是光谱的一端——对集群的所有信息进行高度概述. 而 节点统计值 API 则是在另一端.它提供一个让人眼花缭乱的统计数据的数组,包含集群的每一个节点统计值. 节点统计值 提供的统 ...
- 跟我一起透彻理解template模板模式
#include <iostream> using namespace std; //template模式. class Base { public: void DealWhat() { ...
- python raise assert
class MyException(Exception): def __init__(self,error_msg): self.error_msg=error_msg def __str__(sel ...
- 基于bootstrsp的jquery富文本编辑器的手冊说明
重点:当在页面插入文本编辑器后.无法用js/jq的方式去将某些值写入到文本编辑器.如:$("textarea").val("111");$("text ...
- 操作LOG文件-删除log目录下,所有的空文件-删除5天前的文件
# 1.logs目录下,有一部分文件是空的# 1.删除log目录下,所有的空文件# 2.删除5天前的文件 # 需求分析:# 1.os.walk()获取到所在以.log结尾的文件# 2.判断文件的大小, ...
- HTTP协议图解
1.HTTP简介 http是用于客户端与服务端之间的通信 实际情况中客户端与服务端角色有可能互换,但从一条通信线路来说服务器端和客户端角色是确定的,http协议知道那个是服务端那个是客户端呢. htt ...
- Iocomp控件教程之LinearGauge--线性刻度尺控件
线性刻度尺-线性刻度尺控件(LinearGauge)是一个具有线性表达式刻度的图像控件.支持多达5种颜色断面和4种指示器样式,相同功能,查看线性对数刻度尺(Linear Log Gauge)控件内容 ...
- Linux系统防CC攻击自动拉黑IP增强版Shell脚本 《Linux系统防CC攻击自动拉黑IP增强版Shell脚本》来自张戈博客
前天没事写了一个防CC攻击的Shell脚本,没想到这么快就要用上了,原因是因为360网站卫士的缓存黑名单突然无法过滤后台,导致WordPress无法登录!虽然,可以通过修改本地hosts文件来解决这个 ...