称号:hdoj 5087 Revenge of LIS II 题意:非常easy,给你一个序列,让你求第二长单调递增子序列. 分析:事实上非常easy.不知道比赛的时候为什么那么多了判掉了. 我们用O(n^2)的时间求单调递增子序列的时候,里面在加一层循环维护sum数组.表示前面有几个能够转移当当前,求前面sum的和保存到当前. 最后求最后一个sum[n-1]是否为1就ok.为1的话在最长的基础上减一,否则就是最长的. AC代码: #include <iostream> #include &l…
DP的时候记录下能否够从两个位置转移过来. ... Revenge of LIS II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 393    Accepted Submission(s): 116 Problem Description In computer science, the longest increasing su…
http://acm.hdu.edu.cn/showproblem.php?pid=5087 题意求第二长的上升序列. 在求最长上升序列的同时加上一个数组,来记录以i为结尾的有多少条序列.如果n+1为结尾有多条,就输出dp[n+1]-1; 否则在这个最长的序列上每一个节点是不是都是num[i]==1,如果是,就输出dp[n+1]-2;否则输出dp[n+1]-1: #include <cstdio> #include <cstring> #include <algorithm&…
题意: N个数,求第二长上升子序列的长度. 数据范围: 1. 1 <= T <= 1002. 2 <= N <= 10003. 1 <= Ai <= 1 000 000 000 思路: 数据给的很暧昧,用n^2的算法可以过.故用n^2算法.只要在DP过程中记录得到f[i]是否只有一种方法即可.详看代码. 代码: int T,n; int a[1005],f[1005]; bool NOTalone[1005]; int main(){ //freopen("t…
链接:hdu 5087 题意:求第二大的最长升序子序列 分析:这里的第二大指的是,全部的递增子序列的长度(包含相等的), 从大到小排序后.排在第二的长度 cid=546" style="color:rgb(106,57,6); text-decoration:none">BestCoder Round #16 上的第二题,注意  1 1 2 这组数据,答案应为2 思路1.每次将最长的两个上升子序列长度记录.最后再排序,取第二大的就可以 思路2.假设最长的上升子序列长度(…
Revenge of LIS II Problem DescriptionIn computer science, the longest increasing subsequence problem is to find a subsequence of a given sequence in which the subsequence's elements are in sorted order, lowest to highest, and in which the subsequence…
Revenge of LIS II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 444    Accepted Submission(s): 143 Problem Description In computer science, the longest increasing subsequence problem is to fi…
HDURevenge of Segment Tree(第二长的递增子序列) 题目链接 题目大意:这题是求第二长的递增子序列. 解题思路:用n^2的算法来求LIS,可是这里还要记录一下最长的那个序列是否有多种组成方式,假设>= 2, 那么第二长的还是最长的LIS的长度,否则就是LIS - 1: 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; cons…
一.动态规划的基本思想 动态规划算法通常用于求解具有某种最优性质的问题.在这类问题中,可能会有许多可行解.每一个解都对应于一个值,我们希望找到具有最优值的解. 将待求解问题分解成若干个子问题,先求解子问题,然后从这些子问题的解得到原问题的解.适合于用动态规划求解的问题,经分解得到子问题往往不是互相独立的.若用分治法来解这类问题,则分解得到的子问题数目太多,有些子问题被重复计算了很多次.如果我们能够保存已解决的子问题的答案,而在需要时再找出已求得的答案,这样就可以避免大量的重复计算,节省时间.为了…
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13194    Accepted Submission(s): 5807Special Judge Problem Description FatMouse believes that the fatter a mouse is, the faster i…
最长单调递增子序列 解题思想:动态规划 1.解法1(n2) 状态:d[i] = 长度为i+1的递增子序列的长度 状态转移方程:dp[i] = max(dp[j]+1, dp[i]); 分析:最开始把dp数组初始化为1,然后从前往后考虑数列的元素,对于每个aj,如果a[i] > a[j],就用dp[i] = max(dp[i], dp[j] + 1)进行更新,再从dp数组中找出最大值即为结果 举例:abklmncdefg    dp[0] = 1; dp[1] = 2; dp[2] = 3; dp…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5087 题目意思:找出第二个最长递增子序列,输出长度.就是说,假如序列为 1 1 2,第二长递增子序列是1 2(下标为2 3),而第一长递增子序列也是(下标为 1 3). 我一开始天真的以为,还是利用求最长递增子序列的算法啦,第二长不就是对dp 数组sort完后(从小到大)的dp[cnt-1] 啦,接着就呵呵啦----= = 题解说,要加多一个 dp 数组,以便对当前下标值为 i 的数 a[i] 为结…
题目链接:pid=5087">http://acm.hdu.edu.cn/showproblem.php?pid=5087 题意: 求第二长的最长递增序列的长度 分析: 用step[i]表示以i结尾的最长上升序列的长度,dp[i]表示到i的不同的最长的子序列的个数 然后最后推断最长的子序列的个数是否大于1是的话输出Max,否则输出Max-1 代码例如以下: #include<cstdio> #include<cstring> #include<algorith…
只要理解了LIS,这道题稍微搞一下就行了. 求LIS(最长上升子序列)有两种方法: 1.O(n^2)的算法:设dp[i]为以a[i]结尾的最长上升子序列的长度.dp[i]最少也得是1,就初始化为1,则dp[i]=max(dp[i],dp[j]+1)(其中j<i且a[j]<a[i]). int gao() { ; ;i<n;i++) { dp[i]=; ;j<i;j++) { if(a[j]<a[i]) { dp[i]=max(dp[i],dp[j]+); } } ans=ma…
位运算.. .. Revenge of Nim II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 229    Accepted Submission(s): 79 Problem Description Nim is a mathematical game of strategy in which two players take…
Problem Description In computer science, the longest increasing subsequence problem is to find a subsequence of a given sequence in which the subsequence's elements are in sorted order, lowest to highest, and in which the subsequence is as long as po…
https://www.51nod.com/tutorial/course.html#!courseId=12 解题关键: 如果将子序列按照长度由短到长排列,将他们的最大元素放在一起,形成新序列$B\left\{ {{b_1},{b_2}, \ldots  \ldots ,{b_j}} \right\}$,则序列$B$满足${b_1} < {b_2} <  \ldots  \ldots  < {b_j}$.这个关系比较容易说明,假设${b_{xy}}$表示序列A中长度为$x$的递增序列中…
Bridging signals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12251   Accepted: 6687 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 c…
题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=17 分析: i=1 dp[i]=1 i!=1 dp[i]=max(dp[j]+1)  j<i&&a[j]<a[i] 代码如下: #include<bits/stdc++.h> using namespace std; int main() { int n; scanf("%d",&n); getchar(); while(…
[抄题]: Given an unsorted array of integers, find the length of longest continuous increasing subsequence (subarray). Example 1: Input: [1,3,5,4,7] Output: 3 Explanation: The longest continuous increasing subsequence is [1,3,5], its length is 3. Even t…
LIS(最长递增子序列)和LCS(最长公共子序列)的总结 最长公共子序列(LCS):O(n^2) 两个for循环让两个字符串按位的匹配:i in range(1, len1) j in range(1, len2) s1[i - 1] == s2[j - 1], dp[i][j] = dp[i - 1][j -1] + 1; s1[i - 1] != s2[j - 1], dp[i][j] = max (dp[i - 1][j], dp[i][j - 1]); 初始化:dp[i][0] = dp…
In the army, a platoon is composed by n soldiers. During the morning inspection, the soldiers are aligned in a straight line in front of the captain. The captain is not satisfied with the way his soldiers are aligned; it is true that the soldiers are…
Revenge of Nim II Problem DescriptionNim is a mathematical game of strategy in which two players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects provided th…
称号:pid=2121" target="_blank">hdoj 2121 Ice_cream's world II 题意:题目是一道躶题,给n个点,m条边的有向图.然后找一个点.到全部点的距离和最小.找出这个点并输入距离. 分析:非常明显是求一个最小树形图,可是没有说根节点.要找跟节点,我们能够虚拟一个节 点 x .x 到全部节点连边距离为前面全部距离和+1为 dis . 然后从x 节点求一次最小树形图为ans,则ans - dis 就是最小树形图的距离. 假设图不…
lis: 复杂度nlgn #include<iostream> #include<cstdio> using namespace std; ],lis[],res=; int solve(int x) { ,b=res; while(a!=b) { ; if(lis[mid]>=x) b=mid; else a=mid+; } return a; } int main() { int n; cin>>n; ;i<=n;i++) scanf("%d&…
求最长上升子序列的三种经典方案: 给定一个长度为 \(N\) 的数列,求它数值单调递增的子序列长度最大为多少.即已知有数列 \(A\) , \(A=\{A_1,A_2....A_n\}\) ,求 \(A\) 的任意子序列 \(B\) ( \(B=\{A_{k_1},A_{k_2}....A_{k_p}\}\) ),使 \(B\) 满足 \(k_1<k_2<....<k_p\) 且 \(B=\{A_{k_1}<A_{k_2}<....<A_{k_p}\}\) .求 \(p…
单调递增最长子序列 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 求一个字符串的最长递增子序列的长度如:dabdbf最长递增子序列就是abdf,长度为4   输入 第一行一个整数0<n<20,表示有n个字符串要处理随后的n行,每行有一个字符串,该字符串的长度不会超过10000 输出 输出字符串的最长递增子序列的长度 样例输入 3 aaa ababc abklmncdefg 样例输出 1 3 7 [分析] [代码] #include <cstdio>…
题目:区间的有多少个数字满足数字的每一位上的数组成的最长递增子序列为K 思路:用dp[i][state][j]表示到第i位状态为state,最长上升序列的长度为k的方案数.那么只要模拟nlogn写法的最长上升子序列的求法就行了.这里这里记忆化的时候一定要写成dp[pos][stata][k],表示前pos位,状态为state的,最长上升子序列长为k的方案数这里如果写成dp[pos][state][len]时会出错,因为有多组样例,每一组的k的值不同,那么不同k下得出的dp[pos][state]…
LIS问题 https://www.acwing.com/problem/content/898/ 思路:首先数组a中存输入的数(原本的数),开辟一个数组f用来存结果,最终数组f的长度就是最终的答案:假如数组f现在存了数,当到了数组a的第i个位置时,首先判断a[i] > f[cnt] ? 若是大于则直接将这个数添加到数组f中,即f[++cnt] = a[i];这个操作时显然的.当a[i] <= f[cnt] 的时,我们就用a[i]去替代数组f中的第一个大于等于a[i]的数,因为在整个过程中我们…
题目:[NOIP1999]拦截导弹 问题编号:217 题目描述 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能高于前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹. 输入格式 输入数据为两行, 第一行为导弹的数目N(n<=1000) 第二行导弹依次飞来的高度,所有高度值均为不大于30000的正整数. 输出格式 输出只有一行是这套系…