HDU 2084 数塔

题解:经典数塔问题

#include <cstdio>
#include <iostream>
using namespace std;
#define rep(i,m,n) for(int i=m;i<=n;i++)
int f[100][100];

int max(int a,int b)
{return(a>b?a:b);}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(f,0,sizeof(f));
        int n;
        scanf("%d",&n);
        rep(i,1,n)rep(j,1,i)scanf("%d",&f[i][j]);
        for(int i=n-1; i; i--)rep(j,1,i)
        f[i][j]=f[i][j]+max(f[i+1][j],f[i+1][j+1]);
        printf("%d\n",f[1][1]);
    }
    return 0;
}

 

posted @ 2014-01-22 09:56  forever97  阅读(124)  评论(0编辑  收藏  举报