1004 - Monkey Banana Problem
Time Limit: 2 second(s) Memory Limit: 32 MB

link

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

Output for 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

Case 1: 63

Case 2: 5

Note

Dataset is huge, use faster I/O methods.


SPECIAL THANKS: JANE ALAM JAN (DESCRIPTION, SOLUTION, DATASET)

说白了这道题就是两个数字三角形,一个正的,一个倒过来的;倒着的做法与数字三角形一样,只需要处理正的;

我们来看样例,把这个分为上下两部分,下面就是个倒的数字三角形,正的三角形其实与倒的处理方式类似,我们做数字三角形是从下往上推,或者从上往下推,如果两种都会的话这道题没什么问题了;

博主其实做这个以前都是从下往上推的,但这题分为两部分就不好处理了,所以我选择正三角形从上往下推,而倒三角形相当于一个正的三角形从下往上推,做法不就和纯的数字三角形一模一样了;若不懂来看代码;

#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
//const int INF=0x3f3f3f3f;
const int N=200+10;//开二维数组足够了,没有用到空间压缩;
long long a[N][N];
int main()
{
int t,n,i,j;
memset(a,0,sizeof(a));
scanf("%d",&t);
int t1=t;
while(t--)
{
scanf("%d",&n);
for(i=1; i<=2*n-1; i++)
{
if(i<=n)
{
for(j=1; j<=i; j++)
scanf("%lld",&a[i][j]);//正三角形;
}
else
{
for(j=1; j<=2*n-i; j++)//倒三角;
scanf("%lld",&a[i][j]);
}
}
printf("Case %d: ",t1-t);
for(i=2; i<=n; i++)
for(j=1; j<=i; j++)
a[i][j]+=max(a[i-1][j-1],a[i-1][j]);//从上往下,状态转移方程;
for(i=n+1; i<=2*n-1; i++)
for(j=1; j<=2*n-i; j++)
a[i][j]+=max(a[i-1][j],a[i-1][j+1]);//状态转移方程几乎一样
printf("%lld\n",a[2*n-1][1]);注意格式,博主用I64dPEI
}
return 0;
}

Light oj-1004 - Monkey Banana Problem,数字三角形的变形版~的更多相关文章

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

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

  2. Lightoj 1004 - Monkey Banana Problem

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

  3. Monkey Banana Problem LightOJ - 1004

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

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

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

  5. F - Monkey Banana Problem

    F - Monkey Banana Problem Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & ...

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

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

  7. [LightOJ1004]Monkey Banana Problem(dp)

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

  8. Light OJ Dynamic Programming

    免费做一样新 1004 - Monkey Banana Problem 号码塔 1005 - Rooks 排列 1013 - Love Calculator LCS变形 dp[i][j][k]对于第一 ...

  9. HDU 1176 免费馅饼 (类似数字三角形的题,很经典,值得仔细理解的dp思维)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1176 免费馅饼 Time Limit: 2000/1000 MS (Java/Others)     ...

随机推荐

  1. bzoj 1858: [Scoi2010]序列操作 || 洛谷 P2572

    记一下:线段树占空间是$2^{ceil(log2(n))+1}$ 这个就是一个线段树区间操作题,各种标记的设置.转移都很明确,只要熟悉这类题应该说是没有什么难度的. 由于对某区间set之后该区间原先待 ...

  2. C#---数据库访问通用类、Access数据库操作类、mysql类 .[转]

    原文链接 //C# 数据库访问通用类 (ADO.NET)using System;using System.Collections.Generic;using System.Text;using Sy ...

  3. java数组实现买彩票(通过标识符进行判断的思想)

    package com.wh.shuzu; import java.util.Random; import java.util.Scanner; /** * 买彩票 * @author 王拥江同学 * ...

  4. 12c pdb expdp use DATA_PUMP_DIR meet ORA-39145

    ORA-39002: invalid operation ORA-39070: Unable to open the log file. ORA-39087: directory name DATA_ ...

  5. solr之~模糊查询【转】

    solr之~模糊查询 有的时候,我们一开始不可能准确地知道搜索的关键字在 Solr 中查询出的结果是什么,因此,Solr 还提供了几种类型的模糊查询.模糊匹配会在索引中对关键字进行非精确匹配.例如,有 ...

  6. C#特性的介绍及应用场景

    1.特性的任务:特性就是为了支持对象添加一些自我描述的信息,不影响类封装的前提添加额外信息.如果你用这个信息,那特性就有用:如果你不需要这个信息,那么这个特性就没用. 2.特性的基类:Attribut ...

  7. P1603 斯诺登的密码

    题目背景 根据斯诺登事件出的一道水题 题目描述 题目描述 2013年X月X日,俄罗斯办理了斯诺登的护照,于是他混迹于一架开往委内瑞拉的飞机.但是,这件事情太不周密了,因为FBI的间谍早已获悉他的具体位 ...

  8. greenplum4.3.8.2安装

    GREENPLUM总体结构:   数据库由Master Severs和Segment Severs通过Interconnect互联组成. Master主机负责:建立与客户端的连接和管理:SQL的解析并 ...

  9. [Windows Server 2012] 阿里云镜像购买和使用方法

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将演示:阿里云镜像购买 ...

  10. COGS.1200 ganggang的烦恼

    背景 Zhang Gangrui 年纪大了,记性不好,保险箱的密码记不住了,他只记得密码是一个数的阶乘各个位的数相加的和,最后还有个T或F,代表这个数是否为素数,正好,你到他家去了,他请你帮他这个忙, ...