枚举每个位置,求以num[i]为起点的最长不下降子序列和以num[i]为结尾的最长不递增子序列. 并且把相同值的个数统计一下,最后要减去算重复了的. 比如: 1 9 4 4 2 2 2 3 3 3 7 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; + ; int n; int num[MAXN]; int stack1[MAXN]; int stack2[MA…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4604 这个题解有点问题,暂时没时间改,还是参考别人的吧 #include <cstdio> #include <cmath> #include <algorithm> #include <iostream> #include <cstring> #include <queue> #include <vector> #defin…
题目链接 本来就对N*log(N)算法不大会....然后各种跪了,求出最长不下降+最长不上升-最少相同元素.求相同元素,用二分求上界搞的.代码里4个二分.... #include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include <algorithm> using namespace std; ]; ]; ]; ]; ]; int n; int bi…
从后向前对已搜点做两遍LIS(最长不下降子序列),分别求出已搜点的最长递增.递减子序列长度.这样一直搜到第一个点,就得到了整个序列的最长递增.递减子序列的长度,即最长递减子序列在前,最长递增子序列在后,得到题目所求的双端队列的最长不下降子序列. 注意要去重,当发生替换之后,同种元素在两个序列中的数量不同.为得到最长序列,当然是把少的去掉,留下多的. 5 2 1 2 2 3 #include<stdio.h> #include<cstring> #include<vector&…
6357. Hills And Valleys 自己感觉这是个好题,应该是经典题目,所以半路选手补了这道字符串的动态规划题目. 题意就是给你一个串,翻转任意区间一次,求最长的非下降子序列. 一看题面写的0≤Ai≤9 (i=1,2,⋯,n).就知道肯定有点东西,只要这么写,肯定就是有某个神奇的操作可以解决这道题目. 比赛的时候脑壳都要炸了也没想出来,补题的时候懂了,我可以定义一个b串为0123456789,这肯定是递增的,所以我翻转b的某个区间,然后去和a匹配,因为我把b再翻转回来,还是递增的.…
hdu 6197 题意:给定一个数组,问删掉k个字符后数组是否能不减或者不增,满足要求则是magic array,否则不是. 题解:队友想的思路,感觉非常棒!既然删掉k个后不增或者不减,那么就先求数组的最长不下降子序列的长度l1和最长不上升子序列的长度l2,若l1>=n-k||l2>=n-k,则满足要求. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm&g…
题意: FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the s…
最长上升子序列.最长不下降子序列,解法差不多,就一点等于不等于的差别,我这里说最长不下降子序列的. 有两种解法. 一种是DP,很容易想到,就这样: REP(i,n) { f[i]=; FOR(j,,i-) ); } DP是O(n^2)的,我感觉已经不错了不过还有超碉的nlogn的方法. nlogn的方法: 用栈和二分查找. 遇到一个元素a[i],若它不小于栈顶s[top],直接入栈:若小于栈顶,则在栈中二分查找,用它替换栈中比它大的第一个元素.最终栈的大小就是最长不下降子序列的长度(栈中元素并不…
C - DP Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1025 uDebug Description   Input   Output   Sample Input   Sample Output   Hint   Description JGShini…
#include<stdio.h> ] , temp[] ; int n , top ; int binary_search (int x) { ; int last = top ; int mid ; while (fir <= last ) { mid = (fir + last) / ; if ( x <= temp[mid] ) { last = mid - ; } else { ] ) ; else fir = mid + ; } } } int main () { //…