还算是简单的DP问题,状态方程也不难。刚开始一看还以为是最长连续序列的最大值,想了老半天想不出状态方程。
1 #include<stdio.h> 2 #include<string.h> 3 #define doumax(a,b) (a>b?a:b) 4 const int maxn=1000+5; 5 int a[maxn],d[maxn]; 6 int main() 7 { 8 int n; 9 while(scanf("%d",&n)==1 && n){ 10 for(int i=1;i<=n;i++) 11 scanf("%d",&a[i]); 12 memset(d,0,sizeof(d)); 13 int maxscore=0; 14 for(int i=1;i<=n;i++){ 15 d[i]=a[i]; 16 for(int j=1;j<=i;j++) 17 if(a[j]<a[i]) 18 d[i]=doumax(d[i],d[j]+a[i]); 19 if(maxscore<d[i]) 20 maxscore=d[i]; 21 } 22 printf("%d\n",maxscore); 23 } 24 return 0; 25 }
HDU - 1087 Super Jumping! Jumping! Jumping!,布布扣,bubuko.com
HDU - 1087 Super Jumping! Jumping! Jumping!
原文:http://www.cnblogs.com/BMESwimming/p/3854296.html