ZOJ-1986

来源:互联网 发布:java并发线程好书 编辑:程序博客网 时间:2024/06/05 04:22

和2136基本一样,赤裸的LIS最长上升子序列,可以看下那题的题解,这题据说必须要用O(nlogn)算法,否则会超时。就需要多写一个二分查找的方法而已,本题由于序列没有相同的元素,那个二分查找也感觉有点土,没有判断相等的情况,够这题用就行了

#include<stdio.h>static int bst(int *a, int total, int num){int center, low = 0, high = total - 1;while (low < high){center = (low + high) / 2;if (a[center] < num)low = center + 1;elsehigh = center;}return high;}int main(){int n, a[40000];scanf("%d", &n);while (n--){int p, num, index = 0;scanf("%d", &p);while (p--){scanf("%d", &num);if (!index || num > a[index - 1])a[index++] = num;elsea[bst(a, index, num)] = num;}printf("%d\n", index);}return 0;}


0 0
原创粉丝点击