题解 | #最大上升子序列和#
最大上升子序列和
http://www.nowcoder.com/practice/dcb97b18715141599b64dbdb8cdea3bd
#include<iostream>
using namespace std;
int main()
{
int k,ans = 0;
int height[1000]{0},dp[1000];
cin >> k;
for(int i = 0;i < k;++i)
cin >> height[i];
for(int i = 0;i < k;++i){
dp[i] = height[i];
for(int j = 0;j < i;++j){
if(height[j] < height[i])
dp[i] = max(dp[j] + height[i],dp[i]);
}
ans = max(ans,dp[i]);
}
cout << ans;
}