HDU 1087 Super Jumping! Jumping! Jumping!

Posted jpphy0

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 1087 Super Jumping! Jumping! Jumping!相关的知识,希望对你有一定的参考价值。

链接

Super Jumping! Jumping! Jumping! - http://acm.hdu.edu.cn/showproblem.php?pid=1087

分析

  • LIS
  • 离散化
  • 动态规划
  • 最后一个棋子值相同,访问值最大者最优

代码

/* hdu 1087 Super Jumping! Jumping! Jumping! */
#include <bits/stdc++.h>
using namespace std;
#define MXN 1010
int n, dp[MXN], ans;
struct node{
	int x, y;
}a[MXN];
int main(){
	int b[MXN], cnt;
    while(scanf("%d", &n), n){
		for(int i = 1; i <= n; ++i) scanf("%d", &a[i].x), b[i] = i;
		sort(b+1, b+n+1, [](int x, int y){
			return a[x].x < a[y].x;
		});
		cnt = 1, a[b[1]].y = cnt;
		for(int i = 2; i <= n; ++i){
			if(a[b[i]].x == a[b[i-1]].x ) a[b[i]].y = cnt;
			else a[b[i]].y = ++cnt;
		}
		memset(dp, 0, sizeof dp);
		ans = 0;
		for(int i = 1; i <= n; ++i) {
			for(int j = 0; j < a[i].y; ++j){
				dp[a[i].y] = max(dp[a[i].y], dp[j]+a[i].x);
				if(ans < dp[a[i].y]) ans = dp[a[i].y];
			}
		}
		printf("%d\\n", ans);
    }
    return 0;
}

以上是关于HDU 1087 Super Jumping! Jumping! Jumping!的主要内容,如果未能解决你的问题,请参考以下文章

Super Jumping! Jumping! Jumping! HDU - 1087

HDU-1087 Super Jumping! Jumping! Jumping!

HDU 1087Super Jumping! Jumping! Jumping!

HDU 1087 Super Jumping! Jumping! Jumping!

HDU 1087 Super Jumping! Jumping! Jumping!

HDOJ/HDU 1087 Super Jumping! Jumping! Jumping!(经典DP~)