-
时间:2016-03-27 15:51:40 星期日
-
题目编号:[2016-03-27][HDU][1087][Super Jumping! Jumping! Jumping!]
-
分析:dp[i]表示跳到第i个位置,能拿到的最多分,则dp[i] = max(dp[i] , dp[j] + v[i]) 能从j跳到i
-
遇到的问题:排序之和,a[1].v <= a[2].v 而不是 a[1].v < a[2].v 所以还是需要判断一下价值
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long LL;
const int maxn = 1000 + 10;
LL dp[maxn];
struct pos{
int v,id;
pos(int a = -1,int b = -1):v(a),id(b){}
bool operator < (const pos & a){
return v < a.v;
}
}a[maxn];
int main(){
int n;
while(~scanf("%d",&n) && n){
int tmp;
for(int i = 1;i <= n ;++i){
scanf("%d",&tmp);
a[i] = pos(tmp,i);
}
sort(a+1,a+n+1);
LL ans = 0;
for(int i = 1;i <= n ; ++i){
dp[i] = a[i].v;
for(int j = 1;j < i;++j){
if(a[j].id < a[i].id && a[j].v < a[i].v)
dp[i] = max(dp[i] ,dp[j] + a[i].v);
}
ans = max(ans,dp[i]);
}
printf("%I64d\n",ans);
}
return 0;
}
时间: 2024-10-18 15:58:51