Lightoj 1004 - Monkey Banana Problem

1004 - Monkey Banana Problem

   PDF (English) Statistics Forum
Time Limit: 2 second(s) Memory Limit: 32 MB

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. Thejth (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

数塔变形题目 easy

/* ***********************************************
Author        :guanjun
Created Time  :2016/6/8 10:57:05
File Name     :1004.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
    int x,y;
};
struct cmp{
    bool operator()(Node a,Node b){
        if(a.x==b.x) return a.y> b.y;
        return a.x>b.x;
    }
};

bool cmp(int a,int b){
    return a>b;
}
int a[210][210];
int dp[210][210];
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif
    //freopen("out.txt","w",stdout);
    int T,n;
    cin>>T;
    for(int t=1;t<=T;t++){
        cin>>n;
        cle(a);cle(dp);
        for(int i=1;i<=n;i++){
            for(int j=1;j<=i;j++)
                cin>>a[i][j];
        }
        for(int i=n+1;i<=2*n-1;i++){
            for(int j=1;j<=2*n-i;j++)
                cin>>a[i][j];
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=i;j++){
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-1])+a[i][j];
            }
        }
        for(int i=n+1;i<=2*n-1;i++){
            for(int j=1;j<=2*n-i;j++){
                dp[i][j]=max(dp[i-1][j+1],dp[i-1][j])+a[i][j];
            }
        }
        printf("Case %d: %d\n",t,dp[2*n-1][1]);
    }
    return 0;
}
时间: 2024-10-18 01:27:22

Lightoj 1004 - Monkey Banana Problem的相关文章

LightOJ 1004 Monkey Banana Problem (DP 数字三角形)

1004 - Monkey Banana Problem PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB You are in the world of mathematics to solve the great "MonkeyBanana Problem". It states that, a monkey enters into a diamond shaped twodimen

LightOJ 1004 - Monkey Banana Problem 【DP】

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1004 题意:两个数塔相接,求最大的路径和. 解法:简单DP. 代码: #include <stdio.h> #include <ctime> #include <math.h> #include <limits.h> #include <complex> #include <string> #include <

Light OJ 1004 - Monkey Banana Problem dp题解

1004 - Monkey Banana Problem PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB 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 dim

(LightOJ 1004) Monkey Banana Problem 简单dp

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). Wh

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 s

[LightOJ1004]Monkey Banana Problem(dp)

题目链接:http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1004 题意:数塔的变形,上面一个下面一个,看清楚了直接做就行了. 上半部分转移方程dp(i,j)=max(dp(i-1,j),dp(i-1,j+1))+G(i,j) 下半部分转移方程dp(i,j)=max(dp(i-1,j-1),dp(i-1,j))+G(i,j) 1 #include <algorithm> 2 #include <io

lightoj 1319 - Monkey Tradition (中国剩余定理)

1319 - Monkey Tradition PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB In 'MonkeyLand', there is a traditional game called "Bamboo Climbing". The rules of the game are as follows: 1)       There are N monkeys who play

lightoj 1319 - Monkey Tradition

可以用中国剩余定理也可以用线性同余方程组,时间分别是0.028和0.036 在这个问题里逆元一定有解 #include<bits/stdc++.h> using namespace std; long long p[15];//ans==r[i](mod p[i]) long long r[15]; int n; void extgcd(long long a,long long b,long long &d,long long &x,long long &y)//re

Light OJ Dynamic Programming

免费做一样新 1004 - Monkey Banana Problem 号码塔 1005 - Rooks 排列 1013 - Love Calculator LCS变形 dp[i][j][k]对于第一个字符串i 到jLCS为k的方案数 1068 - Investigation 数位dp 能被K整数且各位数字之和也能被K整除的数 dp[i][j][k] 到第i位每位数字之和的余数为j 当前数字余数为k 1079 - Just another Robbery 01背包 全部钱之和为背包体积 不被抓的