经典数塔DP
自下而上DP
状态转移方程:
DP[I][J]+=MAX (DP[I+1][J],DP[I+1][J+1])
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <sstream>
#include <stdlib.h>
#include <malloc.h>
using namespace std;
int dp[510][510];
int main ()
{
int n;
cin>>n;
memset (dp,0,sizeof(dp));
for (int i=1;i<=n;i++)
for (int j=1;j<=i;j++)
cin>>dp[i][j];
for (int i=n-1;i>=1;i--)
{
for (int j=1;j<=i;j++)
dp[i][j]+=max (dp[i+1][j],dp[i+1][j+1]);
}
cout<<dp[1][1]<<endl;
return 0;
}