您的位置:首页 > 产品设计 > UI/UE

POJ - 2533 Longest Ordered Subsequence(最长上升子序列)

2015-09-26 10:41 429 查看
题目大意:求最长上升子序列

解题思路:裸题

[code]#include <cstdio>
#include <cstring>
const int N = 1010;

int num
;
int n;

int find(int r, int t) {
    int l = 0, mid;
    while (l < r) {
        int mid = (l + r) / 2;
        if (num[mid] < t) l = mid + 1;
        else r = mid;   
    }
    return r;
}

void solve() {
    int top = 0, t;
    num[0] = -1;

    for (int i = 0; i < n; i++) {
        scanf("%d", &t);
        if (t > num[top]) num[++top] = t;
        else  num[find(top, t)] = t;
    }
    printf("%d\n", top);
}

int main() {
    while (scanf("%d", &n) != EOF)  solve();
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: