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的更多相关文章

  1. 2016huasacm暑假集训训练五 F - Monkey Banana Problem

    题目链接:http://acm.hust.edu.cn/vjudge/contest/126708#problem/F 题意:求至上而下一条路径的所经过的值得和最大值,这题比赛时就出了 但当时看不懂题 ...

  2. (LightOJ 1004) Monkey Banana Problem 简单dp

    You are in the world of mathematics to solve the great "Monkey Banana Problem". It states ...

  3. Monkey Banana Problem LightOJ - 1004

    Monkey Banana Problem LightOJ - 1004 错误记录: 1.数组开小2.每组数据数组没有清空 #include<cstdio> #include<cst ...

  4. Light oj-1004 - Monkey Banana Problem,数字三角形的变形版~

                                                                                                     100 ...

  5. Lightoj 1004 - Monkey Banana Problem

    题目链接:http://acm.hust.edu.cn/vjudge/contest/121396#problem/F http://lightoj.com/volume_showproblem.ph ...

  6. [LightOJ1004]Monkey Banana Problem(dp)

    题目链接:http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1004 题意:数塔的变形,上面一个下面一个,看清楚 ...

  7. Light OJ 1004 - Monkey Banana Problem(DP)

    题目大意: 给你一菱形的数字阵,问从最上面走到最下面所能获得的最大值是多少? #include<cstdio> #include<cstring> #include<io ...

  8. Educational Codeforces Round 40 F. Runner's Problem

    Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...

  9. Day9 - F - Monkey and Banana HDU - 1069

    一组研究人员正在设计一项实验,以测试猴子的智商.他们将挂香蕉在建筑物的屋顶,同时,提供一些砖块给这些猴子.如果猴子足够聪明,它应当能够通过合理的放置一些砖块建立一个塔,并爬上去吃他们最喜欢的香蕉.   ...

随机推荐

  1. 利用PPPOE认证获取路由器中宽带账号密码

    前言 回家时买了一台极路由准备换掉家里老掉牙的阿里路由器,想进后台看一下宽带账号密码,咦???后台密码是什么来着??? 我陷入了沉思,家里的路由器一般都是pppoe拨号,而路由器在与pppoe认证服务 ...

  2. haproxy + rabbitmq + keepalived的高可用环境搭建

    一.rabbitmq的搭建:参考rabbimq的安装及集群设置 二.安装和配置haproxy 1.安装haproxyyum install haproxy 2.安装rsysloga. 检查rsyslo ...

  3. Python 最火 IDE 最受欢迎(转载)

    来自:开源中国社区 链接:https://www.oschina.net/news/86973/packt-skill-up-2017 电子书网站 Packt 刚刚发布了第三届 “Skill UP” ...

  4. [iOS 高级] iOS远程推送与本地推送大致流程

    本地推送: UILocalNotification *notification=[[UILocalNotification alloc] init]; if (notification!=nil) { ...

  5. elasticsearch升级步骤

    ES从1.2.1升级到1.4.0 升级步骤,基本上是按照官网的叙述来完成的,链接是:http://www.elasticsearch.org/guide/en/elasticsearch/refere ...

  6. linux中grep命令

    grep 是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来. grep常用用法 [root@www ~]# grep [-acinv] [--color=auto] '搜寻字 ...

  7. 2017.5.1 java动态代理总结

    参考来自:http://www.cnblogs.com/jqyp/archive/2010/08/20/1805041.html 1.代理模式 代理类和委托类有相同接口. 代理类负责为委托类:预处理消 ...

  8. Solidworks草图或者特征无法删除怎么办

      单击重新建模之后即可删除.

  9. iOS开发:Framework的创建

    转载自:http://jonzzs.cn/2017/06/01/iOS%20开发笔记/[iOS%20开发]将自己的框架打包成%20Framework%20的方法/ 环境:Xcode 8 创建 Fram ...

  10. react-native 组件默认属性(defaultProps) 及 属性类型验证(PropTypes)

    1.所有的属性类型 2.代码 import PropTypes from 'prop-types'; type Props = {}; export default class App extends ...