[2016-03-27] [HDU] [1087] [Super jumping! jumping! Jumping!]

Source: Internet
Author: User

    • 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
  
 
  1. #include <algorithm>
  2. #include <cstdio>
  3. using namespace std;
  4. typedef long long LL;
  5. const int maxn = 1000 + 10;
  6. LL dp[maxn];
  7. struct pos{
  8. int v,id;
  9. pos(int a = -1,int b = -1):v(a),id(b){}
  10. bool operator < (const pos & a){
  11. return v < a.v;
  12. }
  13. }a[maxn];
  14. int main(){
  15. int n;
  16. while(~scanf("%d",&n) && n){
  17. int tmp;
  18. for(int i = 1;i <= n ;++i){
  19. scanf("%d",&tmp);
  20. a[i] = pos(tmp,i);
  21. }
  22. sort(a+1,a+n+1);
  23. LL ans = 0;
  24. for(int i = 1;i <= n ; ++i){
  25. dp[i] = a[i].v;
  26. for(int j = 1;j < i;++j){
  27. if ( a [ j Span class= "pun" >. id < a [ i . id && a [ j . v < a [ i . v )
  28. dp[i] = max(dp[i] ,dp[j] + a[i].v);
  29. }
  30. ans = max(ans,dp[i]);
  31. }
  32. printf("%I64d\n",ans);
  33. }
  34. return 0;
  35. }


From for notes (Wiz)

[2016-03-27] [HDU] [1087] [Super jumping! jumping! Jumping!]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.