AcWing 3304. 数字三角形
原题链接
简单
作者:
i_11
,
2021-03-27 15:34:59
,
所有人可见
,
阅读 453
#include <iostream>
using namespace std;
const int N =110;
int f[N][N];
int a[N][N];
int n;
int main()
{
cin >> n;
for (int i = 1 ,k = -(n/2); i <= n ; i ++, k ++)
for (int j = 1 ; j <= i ; j ++)
{
cin >> a[i][j];
if (j <= k || j > i - k) a[i][j] = 0;
}
for (int i = 1 ; i <= n ; i ++) f[n][i] = a[n][i];
for (int i = n - 1 ; i ; i --)
for (int j = 1 ; j <= i ; j ++)
{
f[i][j] = max(f[i + 1][j] + a[i][j], f[i + 1][j + 1] + a[i][j]);
}
cout << f[1][1] << endl;
return 0;
}