F - Monkey Banana Problem
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的更多相关文章
- 2016huasacm暑假集训训练五 F - Monkey Banana Problem
题目链接:http://acm.hust.edu.cn/vjudge/contest/126708#problem/F 题意:求至上而下一条路径的所经过的值得和最大值,这题比赛时就出了 但当时看不懂题 ...
- (LightOJ 1004) Monkey Banana Problem 简单dp
You are in the world of mathematics to solve the great "Monkey Banana Problem". It states ...
- Monkey Banana Problem LightOJ - 1004
Monkey Banana Problem LightOJ - 1004 错误记录: 1.数组开小2.每组数据数组没有清空 #include<cstdio> #include<cst ...
- Light oj-1004 - Monkey Banana Problem,数字三角形的变形版~
100 ...
- Lightoj 1004 - Monkey Banana Problem
题目链接:http://acm.hust.edu.cn/vjudge/contest/121396#problem/F http://lightoj.com/volume_showproblem.ph ...
- [LightOJ1004]Monkey Banana Problem(dp)
题目链接:http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1004 题意:数塔的变形,上面一个下面一个,看清楚 ...
- Light OJ 1004 - Monkey Banana Problem(DP)
题目大意: 给你一菱形的数字阵,问从最上面走到最下面所能获得的最大值是多少? #include<cstdio> #include<cstring> #include<io ...
- Educational Codeforces Round 40 F. Runner's Problem
Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...
- Day9 - F - Monkey and Banana HDU - 1069
一组研究人员正在设计一项实验,以测试猴子的智商.他们将挂香蕉在建筑物的屋顶,同时,提供一些砖块给这些猴子.如果猴子足够聪明,它应当能够通过合理的放置一些砖块建立一个塔,并爬上去吃他们最喜欢的香蕉. ...
随机推荐
- python实现将文件夹内所有txt文件合并成一个文件
新建一个文件夹命名为yuliao,把所有txt文件放进去就ok啦!注意路径中‘/’,windows下路径不是这样. #coding=utf-8 import os #获取目标文件夹的路径 filed ...
- [GraphQL] Reuse Query Fields with GraphQL Fragments
A GraphQL fragment encapsulates a collection of fields that can be included in queries. In this vide ...
- python-mysql-replication
python处理mysql binlog增量日志 http://python-mysql-replication.readthedocs.io/en/latest/examples.html 同样的项 ...
- Android SDK安装时出错“android Failed to rename directory”的解决方法
Android SDK安装时出错"android Failed to rename directory"的解决的方法 安装Android SDK时遇到Failed to r ...
- Archlinux: 优化触摸板配置
在逛 Archlinuxcn BBS 时看到这个帖子: fcitx 输入法看不到选词,上面键盘也不见了! 等待妹子的 依云 提到了 infinality, 并且给出了这个链接: fix-infinal ...
- Android——点击对话框上button不关闭对话框
有时候我没可能须要在点击button进行一些检測.可是并不想关闭次对话框(系统默认点击不论什么一个button则关闭对话框),处理方法例如以下:在点击事件下加入例如以下代码: try { Field ...
- JavaScript单线程(setTimeout,setInterval)
今天看到这篇文章,学到了不少东西 特此发出来 和大家分享 JavaScript的setTimeout与setInterval是两个很容易欺骗别人感情的方法,因为我们开始常常以为调用了就会按既定的方式执 ...
- Android文章收藏
Android集 1.Himi李华明的<Android游戏开发专栏>http://blog.csdn.net/column/details/androidgame.html2.老罗的&l ...
- Ansible 安装jdk
1. 在hosts文件添一个group,里面是你需要安装jdk的ip,如: [newhosts]192.168.2.155 ansible_ssh_user=hadoop ansible_ssh_pa ...
- [Erlang危机](5.1.1)内存
原创文章,转载请注明出处:server非业余研究http://blog.csdn.net/erlib 作者Sunface , and some of the hidden data I mention ...