bzoj 4990(LCS->LIS)
来源:互联网 发布:数据更新维护机制 编辑:程序博客网 时间:2024/06/06 09:47
题意:上下有两个长度为n、位置对应的序列A、B,其中数的范围均为1~n。若abs(A[i]−B[j])<=4,则A[i]与B[j]间可以连一条边。现要求在边与边不相交的情况下的最大的连边数量。注意:保证A和B是全排列n≤1e5
思路:因为是全排列,所以类似大白书上的那个LCS转LIS的思想,记录下a中每个数字出现的位置,然后每读进来一个bi,就把[bi-4,bi+4]的每个合法的数字的位置保存下来,从大到小排个序,然后把n个bi的这个串串起来,最后的LIS就是答案。
#include <bits/stdc++.h>using namespace std;const int maxn = 1e5 + 5;const int INF = 0x3f3f3f3f;int pos[maxn], dp[10 * maxn];int main(){ int n; scanf("%d", &n); for(int i = 1; i <= n; i++) { int x; scanf("%d", &x); pos[x] = i; } vector<int>num; for(int i = 1; i <= n; i++) { int x; scanf("%d", &x); vector<int>vec; for(int j = max(x-4, 1); j <= min(n, x + 4); j++) { vec.push_back(-pos[j]); } sort(vec.begin(), vec.end()); for(int i = 0; i < vec.size(); i++) num.push_back(-vec[i]); } memset(dp, INF, sizeof(dp)); for(int i = 0; i < num.size(); i++) { *lower_bound(dp, dp+num.size(), num[i]) = num[i]; } printf("%d\n", lower_bound(dp, dp+num.size(), INF) - dp); return 0;
阅读全文
0 0
- bzoj 4990(LCS->LIS)
- 子序列(LIS、LCS)
- LCS && LIS
- LIS+LCS~
- LCS?LIS
- LIS&&LCS
- LCS时间复杂度O(NlogN) (LCS 转 LIS)
- NYOJ 题目760 See LCS again(LIS求LCS)
- nyoj See LCS again 760 (LCS&&LIS) 好题
- O(nlogn)实现LCS与LIS
- LIS,LCS,一道LIS题
- bzoj 4993(类LCS)
- LCS/LIS/LCIS
- 动态规划 LCS,LIS
- lis lcs 复杂度
- LCS与LIS
- LCS转为LIS
- LIS LCS LCIS
- oracle:数据库查询返回结果集的默认值
- bzoj 4993(类LCS)
- 区间DP tyvj 1466 最美妙的矩阵
- 4nodejs 的简介与安装
- 【bzoj3165】[Heoi2013]Segment
- bzoj 4990(LCS->LIS)
- JavaEE学习路线图
- java 习题
- 10月集训test17&&test18
- Oracle:rowid、rownum(伪列)
- bzoj 1559 ac自动机 + dfs
- 【NOIP 2014 day1 T3】飞扬的小鸟——题解
- glog简单使用
- PowerDesigner中显示Code和Name