• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

POJ 2533 Longest Ordered Subsequence

Longest Ordered Subsequence
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 29540   Accepted: 12864

Description

A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN) be any sequence (ai1, ai2, ..., aiK), where 1 <= i1 < i2 < ... < iK <= N. For example, sequence (1, 7, 3, 5, 9, 4, 8) has ordered subsequences, e. g., (1, 7), (3, 4, 8) and many others. All longest ordered subsequences are of length 4, e. g., (1, 3, 5, 8).
Your program, when given the numeric sequence, must find the length of its longest ordered subsequence.

Input

The first line of input file contains the length of sequence N. The second line contains the elements of sequence - N integers in the range from 0 to 10000 each, separated by spaces. 1 <= N <= 1000

Output

Output file must contain a single integer - the length of the longest ordered subsequence of the given sequence.

Sample Input

7
1 7 3 5 9 4 8

Sample Output

4

Source

Northeastern Europe 2002, Far-Eastern Subregion
 1 #include <cstdio>
 2 #include <iostream>
 3 #include <vector>
 4 #include <set>
 5 #include <cstring>
 6 #include <string>
 7 #include <map>
 8 #include <cmath>
 9 #include <stack>
10 #include <ctime>
11 #include <algorithm>
12 #include <queue>
13 
14 using namespace std;
15 #define INF 0x7fffffff
16 #define maxm 1001
17 #define mod 1000000007
18 #define mp make_pair
19 #define pb push_back
20 #define rep(i,n) for(int i = 0; i < (n); i++)
21 #define re return
22 #define fi first
23 #define se second
24 #define sz(x) ((int) (x).size())
25 #define all(x) (x).begin(), (x).end()
26 #define sqr(x) ((x) * (x))
27 #define sqrt(x) sqrt(abs(x))
28 #define y0 y3487465
29 #define y1 y8687969
30 #define fill(x,y) memset(x,y,sizeof(x))
31 
32 typedef vector<int> vi;
33 typedef long long ll;
34 typedef long double ld;
35 typedef double D;
36 typedef pair<int, int> ii;
37 typedef vector<ii> vii;
38 typedef vector<string> vs;
39 typedef vector<vi> vvi;
40 
41 template<class T> T abs(T x) { re x > 0 ? x : -x; }
42 const int maxn = 100015;
43 int n, m, t, k, x, l, r, s, sk,y,top,temp;
44 int S[maxn];
45 int main(){
46     top = 0; S[top] = -1;
47     scanf("%d", &n);
48     for (int i = 0; i < n; i++){
49         scanf("%d", &temp);
50         if (temp>S[top])S[++top] = temp;
51         else {
52             int l = 1, r = top;
53             while (l < r){
54                 int mid = (l + r) >> 1;
55                 if (S[mid]<temp)l = mid + 1;
56                 else r = mid;
57             }
58             S[l] = temp;
59         }
60     }
61     printf("%d\n", top);
62 }
View Code
posted @ 2013-12-01 18:44  HaibaraAi  阅读(139)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3