码迷,mamicode.com
首页 > 其他好文 > 详细

登山(LIS变形)

时间:2020-01-29 12:52:20      阅读:69      评论:0      收藏:0      [点我收藏+]

标签:注意   def   lib   namespace   连续   php   bsp   scanf   stream   

登山(LIS变形)

技术图片

 

 

 

注意读题:不连续两个相同海拔,所以要么严格递增,要么严格递减

AC_Code

 

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <string>
 5 #include <cmath>
 6 #include <cstdlib>
 7 #include <queue>
 8 #include <vector>
 9 #include <algorithm>
10 #include <ctime>
11 #include <set>
12 #include <map>
13 using namespace std;
14 typedef long long ll;
15 const int maxn = 1010;
16 
17 int main()
18 {
19     int dp1[maxn]={0}, dp2[maxn]={0}, a[maxn], dp[maxn]={0};
20     int n;
21     scanf("%d",&n);
22     for(int i=1;i<=n;i++){
23         scanf("%d",&a[i]);
24     }
25 
26     for(int i=1;i<=n;i++){
27         for(int j=1;j<i;j++){
28             if( dp1[i]<dp1[j]+1 && a[i]>a[j] ){
29                 dp1[i] = dp1[j]+1;
30             }
31         }
32     }
33 
34     for(int i=n;i>=1;i--){
35         for(int j=n;j>i;j--){
36             if( dp2[i]<dp2[j]+1 && a[i]>a[j] ){
37                 dp2[i] = dp2[j]+1;
38             }
39         }
40     }
41 
42     int maxx=-1;
43     for(int i=1;i<=n;i++){
44         dp[i] = (dp1[i]+1)+(dp2[i]+1)-1;
45         maxx = max(maxx, dp[i]);
46     }
47     printf("%d\n",maxx);
48     return 0;
49 }

 

登山(LIS变形)

标签:注意   def   lib   namespace   连续   php   bsp   scanf   stream   

原文地址:https://www.cnblogs.com/wsy107316/p/12239713.html

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