码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-04-03 09:35:02      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:algorithm   open   isp   scanf   logs   ret   using   get   details   

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

 

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

标签:algorithm   open   isp   scanf   logs   ret   using   get   details   

原文地址:http://www.cnblogs.com/itcsl/p/6661233.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!