include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
using namespace std;
int n;
int dp[510][510];
int a[510][510];
int main()
{
cin >> n;
for(int i=1;i<=n;i)
{
for(int j =1; j<=i;j)
{
cin >>a[i][j];
}
}
for(int i=0;i<=n;i++)
{
for(int j=0;j<=i+1;j++)
{
dp[i][j] = -1000000 ;
}
}
dp[1][1]=a[1][1];
for(int i=2;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
dp[i][j] = max(dp[i-1][j],dp[i-1][j-1]) + a[i][j];
}
}
int mmax=0;
for(int i=1;i<n;i++)
{
if(mmax<dp[n][i])
{
mmax=dp[n][i];
}
}
cout << mmax <<endl;
return 0;
}
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
using namespace std;
int n;
int dp[510][510];
int a[510][510];
int main()
{
cin >> n;
for(int i=1;i<=n;i)
{
for(int j =1; j<=i;j)
{
cin >>a[i][j];
}
}
for(int i=0;i<=n;i++)
{
for(int j=0;j<=i+1;j++)
{
dp[i][j] = -1000000 ;
}
}
for(int i=1;i<=n;i)dp[n][i] = a[n][i];
for(int i=n-1;i>0;i–)
{
for(int j=1;j<=i;j)
{
dp[i][j] = max(dp[i+1][j],dp[i+1][j+1]) + a[i][j];
}
}
cout << dp[1][1] <<endl;
return 0;
}
你是谁
$我第一次见支持数为负数的题解$