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. 批量删除Redis中的key

    bin/redis-cli -h 192.168.46.151 -p 6379 keys "rulelist*" | xargs bin/redis-cli  -h 192.168 ...

  2. 比特币Bitcoin-qt客户端加密前后如何导入导出私钥?

    一.Bitcoin-qt客户端加密后 如需要导出某一地址对应的私钥,需要先调用 walletpassphrase 密码 解锁持续时间(秒), 如:walletpassphrase h123456789 ...

  3. [GraphQL] Reuse Query Fields with GraphQL Fragments

    A GraphQL fragment encapsulates a collection of fields that can be included in queries. In this vide ...

  4. [Algorithms] Classify Mystery Items with the K-Nearest Neighbors Algorithm in JavaScript

    The k-nearest neighbors algorithm is used for classification of unknown items and involves calculati ...

  5. 使用json-server搭建模拟api接口

    转载:http://blog.csdn.net/adojayfan/article/details/55011674 作为前端和客户端开发人员,在后端还没有给出对应的api接口时,我们无法做测试. 这 ...

  6. java学习笔记——可用链表

    NO 链表方法名称 描述 1 public void add(数据类型 对象) 向链表中增加数据 2 public int size() 查看链表中数据个数 3 public boolean isEm ...

  7. 倒计时:CountDownLatch(火箭发射前的准备)读书笔记

     这是一个非常实用的多线程控制工具类,经典的场景就是 火箭发射,在火箭发射前,为了保证万无一失,往往还要进行各项设备,仪器的检查,只有等待所有的检查完毕后,引擎才能点火,      CountDown ...

  8. Nginx:HTTP过滤模块

    参考资料<深入理解Nginx> HTTP过滤模块也是一种HTTP模块,与普通HTTP处理模块不同在于: 1.一个请求仅由一个HTTP处理模块处理,而可以被任意个HTTP过滤模块处理 2.普 ...

  9. MvcPager 分页示例 — 应用CSS样式

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 @model PagedList<string>   <h5>Digg style:</h5> ...

  10. 正则表达式匹配 href 和text内容

    string pattern = @"<a[^>]*href=(""(?<href>[^""]*)""|' ...