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. Codeforces149E - Martian Strings(KMP)

    题目大意 给定一个字符串T,接下来有n个字符串,对于每个字符串S,判断是否存在T[a-b]+T[c-d]=S(1 ≤ a ≤ b < c ≤ d ≤ length(T)) 题解 对于每个字符串S ...

  2. 成都Uber优步司机奖励政策(2月3日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  3. 为Android安装BusyBox

    大家是否有过这样的经历,在命令行里输入adb shell,然后使用命令操作你的手机或模拟器,但是那些命令都是常见Linux命令的阉割缩水版,用起来很不爽.是否想过在 Android上使用较完整的she ...

  4. Java多线程---------同步与死锁:synchronized;等待与唤醒:wait、notify、notifyAll;生命周期

    1.问题的引出 class MyThread implements Runnable{ private int ticket = 5 ; // 假设一共有5张票 public void run(){ ...

  5. 谋哥:App排行榜的秘密

    App在改变世界,改变人们的生活.       如今购物大家都用淘宝.京东,吃饭你会用饭否,看天气预报你用墨迹天气,看视频用优酷.K歌你用唱吧,聊天联系你用微信,看新闻你用今日头条等等.你的生活由你自 ...

  6. 深入理解jQuery插件开发(转)

    如果你看到这篇文章,我确信你毫无疑问会认为jQuery是一个使用简便的库.jQuery可能使用起来很简单,但是它仍然有一些奇怪的地方,对它基本功能和概念不熟悉的人可能会难以掌握.但是不用担心,我下面已 ...

  7. mysql.cnf 配制文件详解

    代码如下: [client]port = 3306socket = /tmp/mysql.sock [mysqld]port = 3306socket = /tmp/mysql.sock basedi ...

  8. MySQL主主复制+LVS+Keepalived实现MySQL高可用性1

    http://bestvivi.com/2015/09/09/MySQL%E4%B8%BB%E4%B8%BB%E5%A4%8D%E5%88%B6+LVS+Keepalived%E5%AE%9E%E7% ...

  9. mydumper工作原理, seconds_behind_master的陷阱和pt-heartbeat (102)

    http://blog.itpub.net/15480802/cid-84815-list-1/

  10. beaglebone-black 在Angstrom系统中的网络配置方法

    Beaglebone Linux 101: Assigning a Static IP Address with Connman Posted on February 6, 2012 by dwatt ...