hdu 1087 Super Jumping! Jumping! Jumping! (最大 上升子序列 线性 dp)

本文提供了一段求解最大上升子序列问题的C++代码实现。通过动态规划的方法,该程序能够找到给定序列中最大上升子序列的权值之和。文章包含了完整的源代码及注释。

http://acm.hdu.edu.cn/showproblem.php?pid=1087

题意:  求最大上升子序列 。。。。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cmath>
 4 #include<iostream>
 5 #include<algorithm>
 6 #include< set>
 7 #include<map>
 8 #include<queue>
 9 #include<vector>
10 #include< string>
11  #define Min(a,b) a<b?a:b
12  #define Max(a,b) a>b?a:b
13  #define CL(a,num) memset(a,num,sizeof(a));
14  #define maxn  1100
15  #define eps  1e-6
16  #define inf 9999999
17  #define read() freopen("data.in","r",stdin) ;
18  using  namespace std;
19  int a[maxn] ;
20  int  dp[maxn] ;
21  int main()
22 {
23      int n , m ;
24      int ans ,i,j;
25       // read() ;
26       while(scanf( " %d ",&n),n)
27     {
28         ans = -inf;
29          for(i =  0 ; i < n;i++)
30         {
31             scanf( " %d ",&a[i]) ;
32         }
33         CL(dp,  0) ;
34          for(i =  0 ; i< n;i++) dp[i] = a[i] ;
35          for(i =  1 ;  i < n;i++)
36         {
37              for(j = i -  1; j >=  0;j -- )
38             {
39                  if(a[i] > a[j])
40                 {
41                     dp[i] = max(dp[i],dp[j] + a[i]) ;
42 
43                 }
44             }
45              if(ans < dp[i]) ans = dp[i] ;
46         }
47         printf( " %d\n ",ans) ;
48     }
49 }

 

转载于:https://www.cnblogs.com/acSzz/archive/2012/10/26/2741808.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值