JamesTang @ 2024-04-23 20:23:12
#include<bits/stdc++.h>
using namespace std;
int log1[1000][1000],re[1000][1000],dp[1000][1000];
int n;
int fun(int x,int y)
{
if(x==n) return log1[x][y];
if(! re[x][y]) re[x][y]=log1[x][y]+max(log1[x+1][y],log1[x+1][y+1]);
return log1[x][y]+max(fun(x+1,y),fun(x+1,y+1));
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=i;j++)
cin>>log1[i][j];
//cout<<"max="<<fun(1,1);
dp[1][1]=log1[1][1];
for(int i=2;i<=n;i++)
for(int j=1;j<=i;j++)
{
dp[i][j]=log1[i][j]+max(dp[i-1][j],dp[i-1][j-1]);
}
int max1=0;
for(int i=1;i<=n;i++)
max1=max(dp[n][i],max1);
cout<<max1;
/*for(int i=1;i<=n;i++)
{for(int j=1;j<=i;j++)
cout<<log1[i][j]<<" ";
cout<<endl;}*/
return 0;
}
by asd123zxc456 @ 2024-04-27 16:20:41
读入数组大小改成1010
by haoyu0119 @ 2024-05-08 23:02:15
@JamesTang @JamesTang @JamesTang @JamesTang @JamesTang @JamesTang @JamesTang @JamesTang @JamesTang @JamesTang
by JamesTang @ 2024-05-15 16:24:14
@asd123zxc456 已AC,感谢回复
by Im_Joker @ 2024-07-09 10:40:12