Hdu 1087 Super Jumping! Jumping! Jumping!

最长上升序列变形。

思路:只要把状态定义改变一下即可,即变为以d[i]变为i为终点的价值最大的序列。

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;

const int MAXN = 1010;
typedef unsigned long long ULL;

ULL A[MAXN];
ULL d[MAXN];
ULL f[MAXN];

int n;

void read_case()
{
	for(int i = 1; i <= n; i++)
	{
		scanf("%llu", &A[i]);
	}
}

void dp()
{
	ULL ans = 0;
	for(int i = 1; i <= n; i++)
	{
		d[i] = A[i];
		for(int j = 1; j <= i-1; j++) if(A[i] > A[j])
		{
			d[i] = max(d[i], d[j]+A[i]);
		}
		if(ans < d[i]) ans = d[i];
	}
	printf("%llu\n", ans);
}

void solve()
{
	read_case();
	dp();
}

int main()
{
	while(scanf("%d", &n) && n)
	{
		solve();
	}
	return 0;
}


你可能感兴趣的:(Hdu 1087 Super Jumping! Jumping! Jumping!)