hdu--2084--dp--数塔

#include<iostream> 
#include<cstring>
using namespace std;
const static int N = 101;
int ar[N][N] = {0};
void dp(int,int);
int n;
int main()
{
    int c;cin>>c;
    while(c--)
    {
        memset(ar,0,sizeof(ar));
        cin>>n;
        for(int i=0;i<n;++i){
            for(int j=0;j<i+1;++j){
                cin>>ar[i][j];
            }
        }
        dp(0,0);
        cout<<ar[0][0]<<endl;
    }
    return 0;
}
void dp(int i,int j){
    if(i < n-1)dp(i+1,j);
    for(int j=0;j<i+1;++j){
        ar[i][j] += ar[i+1][j] > ar[i+1][j+1]?ar[i+1][j] : ar[i+1][j+1];
    }
}
原文地址:https://www.cnblogs.com/langyao/p/7251897.html