hdu 4604 Deque】的更多相关文章

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4604 Deque Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1879    Accepted Submission(s): 689 Problem Description Today, the teacher gave Alice ex…
http://acm.hdu.edu.cn/showproblem.php?pid=4604 将原数组根据其大小关系处理后 使其大小全在10^5内 处理后为 a1,a2,a3.....an 最优deque   b1,b2,b3....bm 先不考虑有相等的情况 假设bj在数组a中出现的最早 对应到a数组中为ai 那么从bj到bm为  以ai为起点到an的最长递增序列(必须包括ai) 用(ai,L)表示 以及从bj到b1为  以ai为起点到an的最长递减序列(必须包括ai)  用(ai,R)表示…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4604 这个题解有点问题,暂时没时间改,还是参考别人的吧 #include <cstdio> #include <cmath> #include <algorithm> #include <iostream> #include <cstring> #include <queue> #include <vector> #defin…
题目大意就是给一个deque 然后有n个数,依次进行操作,每种操作,你可以把这个数放在deque首部,也可以放在尾部,也可以扔掉不管,但是要保证deque中的数是非递减的.最要求deque中最长能是多少 思路是这样的:对于这个序列,最重要的应该是第一个进去的数是什么,然后以该数为开头的最长不升子序列和以该数为开头的最长不降子序列则可以凑成一个最长的序列,当然这两个序列中可能都出现了该数,也就是发生了重复,所以就要减掉重复的部分,即两个子序列中有该数个数较少的序列中这个数应当被减掉. 然后由于数据…
题目链接 本来就对N*log(N)算法不大会....然后各种跪了,求出最长不下降+最长不上升-最少相同元素.求相同元素,用二分求上界搞的.代码里4个二分.... #include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include <algorithm> using namespace std; ]; ]; ]; ]; ]; int n; int bi…
枚举每个位置,求以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…
从后向前对已搜点做两遍LIS(最长不下降子序列),分别求出已搜点的最长递增.递减子序列长度.这样一直搜到第一个点,就得到了整个序列的最长递增.递减子序列的长度,即最长递减子序列在前,最长递增子序列在后,得到题目所求的双端队列的最长不下降子序列. 注意要去重,当发生替换之后,同种元素在两个序列中的数量不同.为得到最长序列,当然是把少的去掉,留下多的. 5 2 1 2 2 3 #include<stdio.h> #include<cstring> #include<vector&…
思路:这题的感觉就是最长上升子序列的升级版.首先对于最长上升子序列要用n*log(n)的算法才行,这个复杂度的算法可以从hdu1025得到启发.然后就是什么情况下最优问题了.对于序列中某个数i,找出其后面最长不下降子序列长度和最长不上升子序列长度,将这两个长度加起来,最大的就是我们要找到.但由于存在相同值,那么我么就要确定这两个子序列中值为i的个数最少的那个,用上面求得和减去它. 我的代码比较挫. #include<iostream> #include<cstring> #incl…
HDU 4602 Partition f[i]表示和为i的方案数.已知f[i]=2i-1. dp[i]表示和为i,k有多少个.那么dp[i]=dp[1]+dp[2]+...+dp[i-1]+f[i-k]. 考虑与f有关的项: f[n-k]是答案的一部分,即2n-k-1是答案的一部分. 把与dp有关的项: 令s[i-1]=dp[1]+dp[2]+...+dp[i-1],那么s[n-1]是答案的一部分. s[i]=s[i-1]+dp[i],又dp[i]=s[i-1]+f[i-k].推出s[i]=2*…
http://acm.hdu.edu.cn/showproblem.php?pid=5818 Joint Stacks Problem Description   A stack is a data structure in which all insertions and deletions of entries are made at one end, called the "top" of the stack. The last entry which is inserted i…