【算法系列学习】[kuangbin带你飞]专题十二 基础DP1 E - Super Jumping! Jumping! Jumping!

https://vjudge.net/contest/68966#problem/E

http://blog.csdn.net/to_be_better/article/details/50563344

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<string>
 5 #include<algorithm>
 6 #include<cmath>
 7 #define INF 0x3f3f3f3f
 8 using namespace std;
 9 int n;
10 const int maxn=1e3+10;
11 int a[maxn];
12 int dp[maxn];
13 int main()
14 {
15     while(scanf("%d",&n)==1&&n)
16     {
17         memset(dp,0,sizeof(dp));
18         for(int i=1;i<=n;i++)
19         {
20             scanf("%d",&a[i]);
21         }
22         for(int i=1;i<=n;i++)
23         {
24             int ans=-INF;
25             for(int k=0;k<i;k++)
26             {
27                 if(a[i]>a[k])
28                 {
29                     ans=max(ans,dp[k]);
30                 }
31             }
32             dp[i]=ans+a[i];
33         }
34         int ans=-INF;
35         for(int i=0;i<=n;i++)
36         {
37             ans=max(ans,dp[i]);
38         }
39         printf("%d\n",ans);
40     }
41     return 0;
42 }
View Code

 

posted @ 2017-04-03 08:23  shulin15  阅读(215)  评论(0编辑  收藏  举报