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

【HDUOJ】1257 最少拦截系统

时间:2018-10-10 00:59:36      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:题解   std   tar   cout   define   long   show   return   lan   

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1257

 

题意:经典题。

 

题解:最长上升子序列。

 

代码:

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <string>
 6 #define ll long long
 7 using namespace std;
 8 const int maxn = 30005;
 9 
10 int a[maxn];
11 int dp[maxn];
12 int main(){
13     int n;
14     while(cin>>n){
15         for(int i = 1; i <= n ;i++){
16             cin>>a[i];
17             dp[i] = 1;
18         }
19         //转成上升
20         for(int i = 1 ;i <= n; i++){
21             for(int j = 1; j < i ;j++){
22                 if(a[j] < a[i]){
23                     dp[i] = max(dp[i],dp[j] + 1);
24                 }
25             }
26         }
27 
28         int maxx = -1;
29 
30         for(int i = 1; i <= n ;i++)
31             maxx = max(dp[i],maxx);
32         cout<<maxx<<endl;        
33     }
34     return 0;
35 }

 

【HDUOJ】1257 最少拦截系统

标签:题解   std   tar   cout   define   long   show   return   lan   

原文地址:https://www.cnblogs.com/Asumi/p/9763853.html

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