Super Jumping! Jumping! Jumping!(dp 水题)
作者:互联网
Super Jumping! Jumping! Jumping!
题意
求从左到右的递增和最大
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int a[2000],dp[2000];
int main()
{
int n;
while(cin>>n,n)
{
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
dp[1]=a[1];
for(int i=2;i<=n;i++)
{
for(int j=1;j<i;j++)
{
if(a[i]>a[j])
{
dp[i]=max(dp[i],dp[j]+a[i]);
}else{
dp[i]=max(a[i],dp[i]);
}
}
}
sort(dp+1,dp+1+n);
cout<<dp[n]<<endl;
}
return 0;
}
标签:水题,int,2000,Jumping,include,Super,dp 来源: https://blog.csdn.net/weixin_43820352/article/details/100847843