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 (≤ ), denoting the number of test cases. Every case starts with an integer N ( ≤ N ≤ ). It denotes that, there will be *N - rows. The ith ( ≤ i ≤ N) line of next N lines contains exactly i numbers. Then there will be N - lines. The jth ( ≤ j < N) line contains N - j integers. Each number is greater than zero and less than . Output
For each case, print the case number and maximum number of bananas eaten by the monkey. Sample Input
Output for Sample Input Case :
Case :

题意 从上到下,使和最大

#include <iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include <math.h>
#include<queue>
#define ll long long
#define INF 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof(a));
#define N 511
using namespace std;
int dp[N][N],a[N][N];
int main()
{
int t,n,con=;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
for(int j=; j<=i; j++)
scanf("%d",&a[i][j]);
}
for(int i=n+; i<*n; i++)
{
for(int j=; j<=*n-i; j++)
scanf("%d",&a[i][j]);
}
met(dp,);
dp[][]=a[][];
for(int i=; i<=n; i++)
{
for(int j=; j<=i; j++)
{
dp[i][j]=max(dp[i][j],dp[i-][j-]+a[i][j]);
dp[i][j]=max(dp[i][j],dp[i-][j]+a[i][j]);
}
}
for(int i=n+; i<*n; i++)
{
for(int j=; j<=*n-i; j++)
{
dp[i][j]=max(dp[i][j],dp[i-][j]+a[i][j]);
dp[i][j]=max(dp[i][j],dp[i-][j+]+a[i][j]);
}
}
printf("Case %d: %d\n",con++,dp[*n-][]);
}
return ;
}

(LightOJ 1004) Monkey Banana Problem 简单dp的更多相关文章

  1. Lightoj 1004 - Monkey Banana Problem

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

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

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

  3. [LightOJ1004]Monkey Banana Problem(dp)

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

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

                                                                                                     100 ...

  5. Monkey Banana Problem LightOJ - 1004

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

  6. F - Monkey Banana Problem

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

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

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

  8. lightoj 1004 dp:数字三角形

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1004 #include <cstdio> #include <cst ...

  9. lightoj 1036 - A Refining Company(简单dp)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1036 题解:设dp[i][j]表示处理到(i,j)点时的最大值然后转移显然是 ...

随机推荐

  1. Storm系列(十)聚流示例

    功能:将多个数据源的数据汇集到一个处理单元进行集中分类处理: 入口类TestMain 1  ; i < size; i++) { 31              content += input ...

  2. HW5.12

    public class Solution { public static void main(String[] args) { printChars('1', 'Z', 10); } public ...

  3. URL参数带中文,后台接收乱码解决方案

    1.前台中文参数用encodeURIComponent()进行编码,如: var textName= encodeURIComponent(name); 2.对整个URL用encodeURI()进行编 ...

  4. java字节流

    一. 字节输入流:InputStream(抽象类,所有字节输入流的超类) 1.FileInputStream:    文件输入流 FileInputStream fileIS = new FileIn ...

  5. JQuery简单实现锚点链接的平滑滚动

    在平时的项目中,我们经常需要一些特效链接,如果使效果进一步加强,我们可以使点击锚点链接平滑滚动到锚点,下面就来给大家讲解下如何使用jQuery来实现.   一般使用锚点来跳转到页面指定位置的时候,会生 ...

  6. 【腾讯优测干货分享】如何降低App的待机内存(五)——优化dex相关内存及本章总结

    本文来自于腾讯优测公众号(wxutest),未经作者同意,请勿转载,原文地址:http://mp.weixin.qq.com/s/01Abwe0p1h3WLh28Tzg_Dw 1.5案例:优化dex相 ...

  7. [Openstack][Grizzly] Mysql删除僵尸实例

    由于某些原因,导致在通过nova delete删除虚拟机后,其task_state 一致处于deleting状态, 但是始终无法删除.由于虚拟机还没有分配到节点等信息,还没有拷贝镜像,所以可以直接从数 ...

  8. JAVA基础入门

    Java入门基础 1.IDE->Eclipse 新建程序步骤 1.创建一个Java项目 2.创建一个包(package) 也就相当于C#中的命名空间C++中的头文件 3.创建一个类 这样就完成了 ...

  9. 正则表达式_matches(Regex)

    [0-9a-zA-Z.%+-] 匹配中括号中的 0-9 或者 a-z 或者 A-Z 或者 . 或者 % 或者 + 或者 - $p = "111,222,333"$p -match ...

  10. excel重复数据

    =COUNTIF(H:H,H1)>1