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;
}
上一篇:A - Super Jumping! Jumping! Jumping!(动态规划DP)


下一篇:Super Jumping! Jumping! Jumping! 最长上升子序列+DP