贼水的dp,看成输出Hint了,,还存了好大的数组。。。。。浪费时间
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=
350+
10;
int mapp[maxn][maxn];
int dp[maxn][maxn];
int n;
int dfs(
int x,
int y)
{
if(dp[x][y]!=-
1)
return dp[x][y];
if(x==n-
1)
return mapp[x][y];
dp[x][y]=max(dfs(x+
1,y),dfs(x+
1,y+
1))+
mapp[x][y];
return dp[x][y];
}
int main()
{
scanf("%d",&
n);
for(
int i=
0; i<n; i++
)
for(
int j=
0; j<=i; j++
)
scanf("%d",&
mapp[i][j]);
memset(dp,-
1,
sizeof(dp));
printf("%d\n",dfs(
0,
0));
return 0;
}
转载于:https://www.cnblogs.com/Wangwanxiang/p/6706883.html
相关资源:数据结构—成绩单生成器