yuanfeirizhan @ 2024-05-21 20:33:49
#include<iostream>
int a[1005][1005],dp[1005][1005];
using namespace std;
int main()
{
int n;
cin >> n;
for(int i=1;i<=n;i++)
{
for (int j = 1; j <= i; j++)
{
cin >> a[i][j];
}
}
for (int i = 1; i <= n; i++)
{
dp[n][i] = a[n][i];
}
for (int i = n - 1; i >=1; i--)
{
for (int j = 1; j <= n-i+1; j++)
{
dp[i][j] = max(dp[i + 1][j], dp[i + 1][j + 1])+a[i][j];
}
}
cout << dp[1][1];
return 0;
}
by Justin_love_coding @ 2024-05-21 20:48:56
@yuanyuan_a12345678
for (int j = 1; j <= n-i+1; j++) 改成for(int j=1;j<=i;j++)
by yuanfeirizhan @ 2024-05-21 20:59:29
过了,谢谢大佬。