水题,经典题,dp题
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
int n,i,j,ans;
int dp[360][360],mp[360][360];
scanf("%d",&n);
for (i=1; i<=n; i++)
{
for (j=1; j<=i; j++)
{
scanf("%d",&mp[i][j]);
}
}
dp[1][1]=mp[1][1];
ans=dp[1][1];
for (i=2; i<=n; i++)
{
dp[i][1]=dp[i-1][1]+mp[i][1];
ans=ans>dp[i][1]?ans:dp[i][1];
for (j=2; j<=i-1; j++)
{
dp[i][j]=mp[i][j]+(dp[i-1][j]>dp[i-1][j-1]?dp[i-1][j]:dp[i-1][j-1]);
ans=ans>dp[i][j]?ans:dp[i][j];
}
dp[i][i]=dp[i-1][i-1]+mp[i][i];
ans=ans>dp[i][i]?ans:dp[i][i];
}
printf("%d\n",ans);
}