Light OJ 1004 - Monkey Banana Problem(DP)

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

 

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
const int INF = 1e9+7;
const int maxn = 1055;
const int MOD = 9973;
int dp[maxn][maxn];
int main()
{
    int n, T, cas = 1;
    scanf("%d", &T);

    while(T--)
    {
        scanf("%d", &n);
        memset(dp, 0, sizeof(dp));
        for(int i=1; i<=n; i++)
        for(int j=1; j<=i; j++)
        {
            scanf("%d", &dp[i][j]);
            dp[i][j] += max(dp[i-1][j-1], dp[i-1][j]);
        }


        for(int i=1; i<=n-1; i++)
        for(int j=1; j<=n-i; j++)
        {
            scanf("%d", &dp[i+n][j]);
            dp[i+n][j] += max(dp[n+i-1][j+1], dp[n+i-1][j]);
        }
        printf("Case %d: %d\n",cas++, dp[2*n-1][1]);
    }
    return 0;
}

 

posted @ 2015-10-21 16:35  向前走丶不回首  阅读(163)  评论(0编辑  收藏  举报