BZOJ1264 [AHOI2006]基因匹配Match 【LCS转LIS】
2018-06-19 20:12
381 查看
题目链接
题解
平凡的\(LCS\)是\(O(n^2)\)的
显然我们要根据题目的性质用一些不平凡的\(LCS\)求法
这就很巧妙了,,
我们考虑\(A\)序列的每个位置可能匹配\(B\)位置的哪些位置
而\(A\)序列中匹配的位置一定是单调递增的
那么我们就把\(A\)的每个位置所能匹配\(B\)的位置找出来,降序排列替代\(A\)原来的位置
我们就能得到一个新的序列,显然原序列的\(LCS\)就是新序列的\(LIS\)
而由于题目的限制,新序列只能使原序列长度的\(5\)倍
而求\(LIS\)是\(O(nlogn)\)的
就可以\(A\)了
比如
A:1 1 1 2 2 2 1 2 2 1
B:1 1 1 1 1 2 2 2 2 2
1对应5 4 3 2 1
2对应10 9 8 7 6
那么新序列 5 4 3 2 1,5 4 3 2 1,5 4 3 2 1,10 9 8 7 6,10 9 8 7 6,10 9 8 7 6,.......
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<map> #include<vector> #define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt) #define REP(i,n) for (int i = 1; i <= (n); i++) #define mp(a,b) make_pair<int,int>(a,b) #define cls(s) memset(s,0,sizeof(s)) #define cp pair<int,int> #define LL long long int using namespace std; const int maxn = 500005,maxm = 100005,INF = 1000000000; inline int read(){ int out = 0,flag = 1; char c = getchar(); while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();} while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();} return out * flag; } vector<int> pos[maxn]; int n,A[maxn],B[maxn],C[maxn],bac[maxn],f[maxn],N,M; int cal(int x){ int l = 0,r = N,mid; while (l < r){ mid = l + r + 1 >> 1; if (bac[mid] < x) l = mid; else r = mid - 1; } return l; } int main(){ n = read(); N = n * 5; REP(i,N) A[i] = read(); REP(i,N) B[i] = read(),pos[B[i]].push_back(i); REP(i,N){ for (unsigned int j = pos[A[i]].size() - 1; ~j; j--) C[++M] = pos[A[i]][j]; } memset(bac,0x3f3f3f3f,sizeof(bac)); bac[0] = 0; int ans = 0; REP(i,M){ f[i] = cal(C[i]) + 1; bac[f[i]] = min(bac[f[i]],C[i]); ans = max(ans,f[i]); } printf("%d\n",ans); return 0; }
相关文章推荐
- 【BZOJ1264】[AHOI2006]基因匹配Match【DP】【LCS】【树状数组】
- BZOJ 1264: [AHOI2006]基因匹配Match( LCS )
- BZOJ 1264 基因匹配Match(LCS转化LIS)
- bzoj 1264: [AHOI2006]基因匹配Match 树状数组
- [bzoj1264] [AHOI2006]基因匹配Match
- 【DP+树状数组】BZOJ1264-[AHOI2006]基因匹配Match
- bzoj 1264: [AHOI2006]基因匹配Match
- BZOJ 1264 基因匹配Match(LCS转化LIS)
- 【BZOJ1264】【AHOI2006】基因匹配Match (dp+树状数组)
- bzoj 1264: [AHOI2006]基因匹配Match (DP+树状数组)
- bzoj 1264: [AHOI2006]基因匹配Match
- BZOJ_1264_[AHOI2006]基因匹配Match_树状数组
- BZOJ 1264 AHOI2006 基因匹配Match 动态规划+树状数组
- bzoj1264 [AHOI2006]基因匹配Match (树状数组优化DP)
- bzoj 1264 [AHOI2006]基因匹配Match(DP+树状数组)
- BZOJ 1264 AHOI2006 基因匹配Match 动态规划+树状数组
- [bzoj1264][AHOI2006]基因匹配Match 树状数组优化dp
- BZOJ 1264: [AHOI2006]基因匹配Match 树状数组,DP
- bzoj 1264 [AHOI2006]基因匹配Match(DP+树状数组)
- BZOJ1264: [AHOI2006]基因匹配Match