HDU-1087.Super Jumping! Jumping! Jumping!

做了动归几道题了,还是没有怎么明白需要怎么用动归解题,状态不怎么找的准,状态转移方程在确定了状态还行,还能想出来,总之还是多做题吧!

#include<iostream>
#include<cstdio>
#include<memory.h>
using namespace std;
int a[1005],d[1005];
int main()
{
   int i,j,n,value;
   while(scanf("%d",&n)&&n){
     memset(d,0,sizeof(d));
     for(i=1;i<=n;i++)
        cin >>a[i];
     value=a[0];
     for(i=1;i<=n;i++){
        for(j=0;j<i;j++){
            if(a[i]>a[j]) d[i]=max(d[i],d[j]+a[i]);
            value=max(value,d[i]);
        }
     }
     cout <<value<<endl;
   }
   return 0;
}

 

你可能感兴趣的:(HDU-1087.Super Jumping! Jumping! Jumping!)