You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.1 KiB

2 years ago
#include <bits/stdc++.h>
using namespace std;
const int N = 510;
int a[N][N];
int n;
/**
1
nn+1
2线
sum(left,right,a[x][y])
3使intsumsum
,int
4
*/
int dfs(int x, int y) {
if (x == n + 1) return 0; // 你们不要指望我了我是0你们该咋办就咋办吧~
if (y > x) return 0;
return max(dfs(x + 1, y), dfs(x + 1, y + 1)) + a[x][y];
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= i; j++)
cin >> a[i][j];
int res = dfs(1, 1);
printf("%d", res);
return 0;
}