- Time: 2016-03-27-15:51:40 Sunday
- Title Number: [2016-03-27][hdu][1087][super jumping! jumping! Jumping!]
- Analysis: dp[i] means to jump to the first position, the most points can be obtained, then dp[i] = max (Dp[i], dp[j] + v[i]) can jump from J to I
- Problems encountered: the sum of sorts, a[1].v <= a[2].v instead of A[1].V < A[2].V so still need to judge the value
#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 Span class= "pun" >. 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;
}
From for notes (Wiz)
[2016-03-27] [HDU] [1087] [Super jumping! jumping! Jumping!]