HDU 1087 Super Jumping! Jumping! Jumping!

emmm

Posted by Zexin Zhang on October 24, 2017

最大上升子序列

因为n==0时不输出,所以加了特判

img

//输入为0时不输出

#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <cmath>

#include <algorithm>

using namespace std;
int dp[1001];
int temp[1001];
int main(){
	int n;
	while(~scanf("%d",&n)){
		if(n!=0){
		memset(dp,0,sizeof(dp));
		memset(temp,0,sizeof(temp));
		for(int i=1;i<=n;i++){
			scanf("%d",&temp[i]);
		}
		int ans=0;
		for(int i=0;i<=n;i++)
			for(int j=0;j<i;j++){
				if(temp[i]>temp[j])
					dp[i]=max(dp[i],dp[j]+temp[i]);
				ans=max(ans,dp[i]);
			}
			printf("%d\n",ans);
		}
		else break;
	}
	return 0;
}