HDU 1950 Bridging signals(LIS)】的更多相关文章

最长上升子序列(LIS)的典型变形,O(n^2)的动归会超时.LIS问题可以优化为nlogn的算法. 定义d[k]:长度为k的上升子序列的最末元素,若有多个长度为k的上升子序列,则记录最小的那个最末元素. 注意d中元素是单调递增的,下面要用到这个性质. 首先len = 1,d[1] = a[1],然后对a[i]:若a[i]>d[len],那么d[++len] = a[i]; 否则,我们要从d[1]到d[len-1]中找到一个j,满足d[j-1]<a[i]<d[j],则根据d的定义,我们需…
解题思路:题目给出的描述就是一种求最长上升子序列的方法 将该列数an与其按升序排好序后的an'求出最长公共子序列就是最长上升子序列 但是这道题用这种方法是会超时的,用滚动数组优化也超时, 下面是网上找的求LIS的算法 假设要寻找最长上升子序列的序列是a[n],然后寻找到的递增子序列放入到数组b中. (1)当遍历到数组a的第一个元素的时候,就将这个元素放入到b数组中,以后遍历到的元素都和已经放入到b数组中的元素进行比较: (2)如果比b数组中的每个元素都大,则将该元素插入到b数组的最后一个元素,并…
Bridging signals Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4452    Accepted Submission(s): 2769 Problem Description 'Oh no, they've done it again', cries the chief designer at the Waferlan…
职务地址:HDU 1950 这题是求最长上升序列,可是普通的最长上升序列求法时间复杂度是O(n*n).显然会超时.于是便学了一种O(n*logn)的方法.也非常好理解. 感觉还用到了一点贪心的思想. 详细的见这篇博客吧,写的非常通俗易懂.传送门 代码例如以下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h>…
题意: 给一个数字序列,要求找到LIS,输出其长度. 思路: 扫一遍+二分,复杂度O(nlogn),空间复杂度O(n). 具体方法:增加一个数组,用d[i]表示长度为 i 的递增子序列的最后一个元素,且该元素总是保持当前最小.初始化d[1]=A[i],当前LIS的长度len=1.从 2 to n,若A[i]>d[len],则d[++len]=A[i],否则,在数组d中找到A[i]应该插入的位置,代替掉那个第一个比它大的数字,比如d[k]<A[i]<=d[k+1],直接将A[i]代替掉d[…
那么一大篇的题目描述还真是吓人. 仔细一读其实就是一个LIS,还无任何变形. 刚刚学会了个二分优化的DP,1A无压力. //#define LOCAL #include <iostream> #include <cstdio> #include <cstring> using namespace std; + ; int a[maxn]; int dp[maxn]; int main(void) { #ifdef LOCAL freopen("1950in.t…
Bridging signals Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 961    Accepted Submission(s): 627 Problem Description 'Oh no, they've done it again', cries the chief designer at the Waferland…
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…
题意:给你一个长为n(n<=40000)的整数序列, 要你求出该序列的最长上升子序列LIS. 思路:要求(nlogn)解法 令g[i]==x表示当前遍历到的长度为i的所有最长上升子序列中的最小序列末尾值为x.(如果到目前为止, 根本不存在长i的上升序列, 那么x==INF无穷大) 假设当前遍历到了第j个值即a[j], 那么先找到g[n]数组的值a[j]的下确界k(即第一个>=a[j]值的g[k]的k值). 那么此时表明存在长度为k-1的最长上升子序列且该序列末尾的位置<j且该序列末尾值&…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1950 Bridging signals Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3711    Accepted Submission(s): 2337 Problem Description 'Oh no, they've don…
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…
Bridging signals 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 blo…
Bridging signals Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2415    Accepted Submission(s): 1570 Problem Description 'Oh no, they've done it again', cries the chief designer at the Waferlan…
这个博客说的已经很好了.http://blog.csdn.net/shuangde800/article/details/7474903 简单记录一下自己学的: 问题就是求一个数列最长上升子序列的长度. 如果子序列长度相同,那么末尾小的子序列更有可能成为最长的子序列.所以就用一个l数组存当子序列长度为len时最小的末尾元素.如果序列下一个值比l[len]大,说明上升子序列长度增加,那么l[len++]=a[i];如果是小,就想办法把它插入到了l数组中.... HDU 1950 说白了就是求lis…
Language: Default Bridging signals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10762   Accepted: 5899 Description 'Oh no, they've done it again', cries the chief designer at the Waferland chip factory. Once more the routing designers…
点击打开链接 B - Bridging signals '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 bloc…
1.链接地址: http://poj.org/problem?id=1631 http://bailian.openjudge.cn/practice/1631 2.题目: Bridging signals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9882   Accepted: 5409 Description 'Oh no, they've done it again', cries the chief des…
Bridging signals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9441   Accepted: 5166 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…
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…
欢迎参加——每周六晚的BestCoder(有米!) Bridging signals Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 941    Accepted Submission(s): 614 Problem Description 'Oh no, they've done it again', cries the chief…
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…
目录 题目链接 题解 代码 题目链接 HDU 4352 XHXJ's LIS 题解 对于lis求的过程 对一个数列,都可以用nlogn的方法来的到它的一个可行lis 对这个logn的方法求解lis时用的数组进行装压 预处理的到这个的转移 数位dp转移的时候直接得到下一位的lis状态 代码 #include<set> #include<cstdio> #include<cstring> #include<algorithm> #define gc getcha…
HDU 4352 XHXJ's LIS HDU 题目大意 给你L到R区间,和一个数字K,然后让你求L到R区间之内满足最长上升子序列长度为K的数字有多少个 solution 简洁明了的题意总是让人无从下手 数字--数位DP 根据题意定义数组 第一维:数位 第二维:数位状态01串 第三维:个数K的大小 说说心路历程: 写的时候没有注意到前导零的可能型(通过看大佬的blog发现的 问题就是如何进行状态转移(手动@LC参考了LC的题解 我们用一个长度为10的二进制数表示数字几有没有被选到 如果为0,则表…
http://acm.split.hdu.edu.cn/showproblem.php?pid=1950 题意:求最长上升(不连续or连续)子序列 推荐博客链接: http://blog.csdn.net/sinat_30062549/article/details/47197073 #include <iostream> #include <stdio.h> #include <string.h> #include <string> #include &l…
题意:题目很难懂,题意很简单,求最长递增子序列LIS. 分析:本题的最大数据40000,多个case.用基础的O(N^2)动态规划求解是超时,采用O(n*log2n)的二分查找加速的改进型DP后AC了. 在基础的动态规划解法中,由于动态规划的无后效性(对于每个阶段来说,它以前的各阶段状态无法直接影响它未来的决策,只能间接地通过当前状态来影响),当我们考察第i+1个元素的时候,我们是不考虑前面i个元素的分布情况的.当我们考虑前面的情况时会发现,对于前面i个元素的任意一个递增子序列,如果这个子序列的…
把左边固定,看右边,要求线不相交,编号满足单调性,其实是LIS的等价表述. (如果编号是乱的也可以把它有序化就像Uva 10635 Prince and Princess那样 O(nlogn) #include<cstdio> #include<iostream> #include<string> #include<cstring> #include<queue> #include<vector> #include<stack&…
题意:左右各n个端口,已知n组线路,要求切除最少的线路,使剩下的线路各不相交,按照左端口递增的顺序输入. 分析: 1.设左端口为l,右端口为r,因为左端口递增输入,l[i] < l[j](i < j),因此若要不相交,r[i] < r[j],由此可以得出,只要求出对应的右端口序列的最长上升子序列的长度即可. 2.最长上升子序列: dp[i]---长度为i+1的上升子序列中末尾元素的最小值(若不存在,则为INT_INF). 如果子序列长度相同,那么最末位元素较小的在之后会更加有优势. #p…
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1950 题意:实际就是求最长递增子序列 题解:有两种解法,一种是利用二分,一种是用线段树 这个是这题的二分代码: #include <cstdio> #include<algorithm> #define F(i,a,b) for(int i=a;i<=b;i++) using namespace std; ; int a[N],d[N]; int LIS(int* a, int…
不能交叉的引脚 (这一题的难度在于读题)题目大意:有一堆引脚(signals),左边一排,右边一排,左边从上到下,对应着连接右边的引脚(所有的引脚都被接上),现在引脚之间的连线有交叉,我们要桥接这些交叉,而桥接是费事的,现在要你求不交叉引脚的最大数目 明白题在说什么以后,是不是感觉豁然开朗? 没错,这一题我们只用把左边的引脚从上到下排列(事实上已经排了),然后看右边对应的引脚的上升序最长有多少就可以了 昨天我弄了一个Wooden Sticks,这一题也要用到LIS,而且还是直接用LIS,更简单…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5489 给你n个数,要删去其中连续的L个,问你删去之后的LIS最大是多少? 我们先预处理出以i下标为开头的LIS,存到数组中. 然后可以枚举长为L的区间,每次移动,左边增加一个,右边删除一个. 最长上升子序列长度 = 窗口右边以右边第一个元素开头的最长上升子序列 + 窗口左边最大元素小于窗口右边第一个元素的最长上升子序列. 比如 1 2 [4 3] 2 3 5  ,  LIS = 3 + 1 = 4…