链接
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;
}