思路
求和最大,划分没子问题,求的每次子问题最大
代码
#include<iostream>
#include<vector>
using namespace std;
const int N = 1010;
int dp[N][N] = {0};
int arr[N][N]={0};
int main(){
int n ;
cin>>n;
int ans = 0;
for(int i = 1;i<=n;i++){
for(int j = 1;j<=i;j++)
cin>>arr[i][j];
}
for(int i = 1;i<=n;i++){
for(int j = 1;j <=n;j++){
dp[i][j] = max(dp[i-1][j],dp[i-1][j-1])+arr[i][j];
ans = max(ans,dp[i][j]);
}
}
cout<<ans;
return 0;
}
标签:arr,int,最大值,三角形,include,dp
From: https://www.cnblogs.com/tsqo/p/16891189.html