[luoguP1439] Arranging LCS problems (DP + tree Array)

Source: Internet
Author: User

Portal

LCS problem with no repeating elements

N2 practice did not say.

Nlogn Practices--

Because the LCS problem is the common subsequence, the order does not affect the answer, the answer is only two strings of the elements are the same, so you can exchange element position.

To simplify the problem first, assuming that P1 happens to be a monotonically increasing,... N, then obviously the answer is the length of the longest ascending subsequence of P2.

The problem is that P1 is not monotonically increasing, but we can assume that it is a one-way,..., N, mapping p1[1] to 1,p1[2] maps to 2 ... The P2 is then transformed in the same way, which requires only the longest ascending subsequence of the P2.

--code

1#include <cstdio>2#include <algorithm>3#include <cstring>4 5 using namespacestd;6 7 Const intMAXN =100001;8 intN, ans;9 intA[MAXN], B[MAXN], C[MAXN];Ten  OneInlineintQueryintx) A { -     intAns =0; -      for(; x; x-= x & x) ans =Max (ans, c[x]); the     returnans; - } -  -InlinevoidUpdateintXintd) + { -      for(; x <= n; x + = x & x) c[x] =Max (c[x], d); + } A  at intMain () - { -     intI, J, X, y; -scanf"%d", &n); -      for(i =1; I <= N; i++) scanf ("%d", &x), a[x] =i; -      for(i =1; I <= N; i++) scanf ("%d", &x), b[i] =A[x]; in      for(i =1; I <= N; i++) -     { toy = query (B[i]-1) +1; + Update (b[i], y); -Ans =Max (ans, y); the     } *printf"%d", ans); $     return 0;Panax Notoginseng}
View Code

[luoguP1439] Arranging LCS problems (DP + tree Array)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.