#include <iostream>
using namespace std;
int flag[101];
int num[101][101];
int main ()
{
int N;
int i , j ;
cin >> N;
memset(flag, 0, sizeof(flag));
for (i = 1; i<=N ; i++)
for (j = 1; j <= i; j++)
scanf ("%d",&num[i][j]);
for (i = 1; i<=N ; i++)
flag[i] = num[N][i];
for (i = N; i>0 ; i--)
for (j = 1; j <i; j++)
{
if (flag[j] + num[i-1][j] > flag[j + 1] + num[i-1][j])
flag[j] = flag[j] + num[i-1][j];
else
flag[j] = flag[j+1] + num[i-1][j];
}
cout << flag[1]<<endl;
return 0;
}
dp求最长序列和问题,题目比较简单,短小精悍!代码:
转载于:https://www.cnblogs.com/Chinese-Coder-Clarence/articles/2039277.html