Lucky_cat @ 2022-06-10 18:54:59
#include <iostream>
#include <algorithm>
#define MAX 200
using namespace std;
int D[MAX][MAX];
int n;
int MaxSum(int i, int j)
{
if(i == n)
return D[i][j];
int x = MaxSum(i + 1,j);
int y = MaxSum(i + 1,j+1);
return max(x,y) + D[i][j];
}
int main()
{
int i,j;
cin >> n;
for(i = 1;i <= n;i++)
for(j = 1;j <= i;j++)
cin >> D[i][j];
cout << MaxSum(1,1) << endl;
}
RT,有RE也有TEL /kk
by Lucky_cat @ 2022-06-10 18:55:30
lz动规基本上没学懂
by BMTXLRC @ 2022-06-10 21:32:56
干嘛要用搜索的形式。为什么不直接循环
by Altwilio @ 2022-06-10 21:43:40
为什么不递推