标签:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 500 + 10;
int dp[maxn][maxn],a[maxn][maxn];
int main(){
int n;
scanf("%d",&n);
memset(dp,0,sizeof(dp));
for(int i = 0 ; i < n ; ++i){
for(int j = 0 ; j <= i ; ++j){
scanf("%d",&a[i][j]);
}
}
dp[0][0] = a[0][0];
int ans = 0;
for(int i = 1 ; i < n ; ++i){
dp[i][0] = dp[i - 1][0] + a[i][0];
ans = max(ans , dp[i][0]);
for(int j = 1 ; j <= i ; ++j){
dp[i][j] = max(dp[i - 1][j] + a[i][j] , dp[i - 1][j - 1] + a[i][j]);
ans = max(dp[i][j] , ans);
}
}
printf("%d\n",ans);
return 0;
}
[2016-05-09][51nod][1002 数塔取数问题]
标签:
原文地址:http://www.cnblogs.com/qhy285571052/p/38221603d53b26acf5113d729299d696.html