Bridging signals Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 667    Accepted Submission(s): 443 Problem Description 'Oh no, they've done it again', cries the chief designer at the Waferland…
用一个数组记下递增子序列长度为i时最小的len[i],不断更新len数组,最大的i即为最长递增子序列的长度 #include<cstdio> #include<algorithm> #define MAX 40010 using namespace std; int a, T, n, len[MAX]; int* lower(int &val, int R) //二分找值,返回下标 { , mid; while (L < R) { mid = R - (R - L +…
题目链接:http://poj.org/problem?id=3903 题目链接:http://poj.org/problem?id=1631 题目链接:http://poj.org/problem?id=1887 题目解析: 这两道题都是直接求最长上升子序列,没什么好说的. POJ 3903这题n为1000000,如果用n^2的算法肯定超时,所以要选择nlogn的算法.都是简单题. #include <iostream> #include <string.h> #include…
LIS nlogn的时间复杂度,之前没有写过. 思路是d[i]保存长度为i的单调不下降子序列末尾的最小值. 更新时候,如果a[i]>d[len],(len为目前最长的单调不下降子序列) d[++len]=a[i] 否则 二分查找 d[j-1]<a[i]<d[j] 并更新 d[j]=a[i]   #include<cstdio> #include<algorithm> #include<cstring> #include<iostream>…
普通做法是O(n^2)下面介绍:最长上升子序列O(nlogn)算法(http://blog.csdn.net/shuangde800/article/details/7474903) /* HDU 1950 Bridging signals -----最长上升子序列nlogn算法 */ #include<cstdio> #include<cstring> #define MAXN 40005 int arr[MAXN],ans[MAXN],len; /* 二分查找. 注意,这个二分…
最长上升子序列(LIS)的典型变形,熟悉的n^2的动归会超时.LIS问题可以优化为nlogn的算法.定义d[k]:长度为k的上升子序列的最末元素,若有多个长度为k的上升子序列,则记录最小的那个最末元素.注意d中元素是单调递增的,下面要用到这个性质.首先len = 1,d[1] = a[1],然后对a[i]:若a[i]>d[len],那么len++,d[len] = a[i];否则,我们要从d[1]到d[len-1]中找到一个j,满足d[j-1]<a[i]<d[j],则根据D的定义,我们需…
Bridging signals Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2354    Accepted Submission(s): 1536 Problem Description 'Oh no, they've done it again', cries the chief designer at the Waferlan…
Bridging signals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9234   Accepted: 5037 Description 'Oh no, they've done it again', cries the chief designer at the Waferland chip factory. Once more the routing designers have screwed up co…
Problem Description 'Oh no, they've done it again', cries the chief designer at the Waferland chip factory. Once more the routing designers have screwed up completely, making the signals on the chip connecting the ports of two functional blocks cross…
最近一直在做<挑战程序设计竞赛>的练习题,感觉好多经典的题,都值得记录. 题意:给你t组数据,每组数组有n个数字,求每组的最长上升子序列的长度. 思路:由于n最大为40000,所以n*n的复杂度不够了,会超时. 书上状态方程换成了d[i]——以长度为i+1的上升子序列中末尾元素的最小值. 那么我们在遍历第i个元素时候,以这个元素为末尾元素的最长子序列也就是在d[i]中找到一个小于num[i]的最大值,然后在这个序列末尾加上num[i] 显然,我们在查找时便可以利用二分搜索,从而把复杂度从原来的…