Bzoj 1264: [AHOI2006] gene matching match (LCS)

Source: Internet
Author: User

Sequence Maximum length 2w * 5 = 10w, O (n²) LCS will T:

LCS only update the answer when a[i] = = B[j], we can record n number of 5 positions in the first sequence, and then sweep the second sequence from left to right to update the value of the corresponding position of the first sequence and maintain it with a tree array. Time complexity O (NLOGN)

-------------------------------------------------------------------------------------------------

#include <bits/stdc++.h>#define REP (i, n) for (int i = 0; i < n; i++)#define CLR (x, C) memset (x, C, sizeof (x))#define LOWBIT (x) ((x) & (-(x ))) using namespace std;const int MAXN = 20009, maxlen = 100009;vector<int> POS[MAXN];int Dp[maxlen], n, Len;void Modify (int p, int v) {For (; P <= len; p + = Lowbit (p))Dp[p] = max (dp[p], v);}int query (int p) {int ans = 0;For (; p; p-= Lowbit (p))ans = max (ans, dp[p]);return ans;} int main () {freopen ("test.in", "R", stdin);CLR (DP, 0);cin >> N;len = n * 5;Rep (i, Len) {int v;scanf ("%d", &v);Pos[v].push_back (i + 1);}Rep (i, Len) {int v;scanf ("%d", &v);For (int j = 4; ~j; j--) {int p = pos[v][j];Modify (P, query (P-1) + 1);}}cout << query (len) << "\ n";return 0;}

-------------------------------------------------------------------------------------------------

1264: [AHOI2006] gene matches match time limit: ten Sec Memory Limit: 162 MB
Submit: Solved: 445
[Submit] [Status] [Discuss] Description gene matching (match) Kaka dreamed last night that he and cocoa had come to another planet, and that the DNA sequence of the creatures on the planet was made up of countless bases (only 4 on earth), and even more strangely, each of the bases that made up the DNA sequence appeared exactly 5 times in that sequence! So if a DNA sequence has n different bases, it must be 5N in length. Kaka woke up to tell the strange dream of cocoa, and cocoa these days are studying the genetic matching problem in bioinformatics, so he decided to write a simple DNA matching program for the creature on this strange planet. In order to describe the principle of gene matching, we need to set the concept of a sub-sequence: If you extract some bases (characters) from a DNA sequence (string) s, and they are still arranged in the order of S in a new string u, you are called a subsequence of S. For two DNA sequences S1 and S2, if there is a sequence u that is also a subsequence of S1 and S2, then U is the common subsequence of S1 and S2. Kaka is known to have two DNA sequences S1 and S2, and the maximum match for S1 and S2 is the length of the longest common sub-sequence of S1 and S2. [Task] Write a program:? Read two equal-length DNA sequences from the input file; calculate their maximum match;? Print the results you get to the output file. The first line in the input file has an integer n, indicating that some species on the planet use n different bases, and they are numbered 1 later ... An integer of N. There are two lines below, each of which describes a DNA sequence: Contains 5N of 1 ... An integer of n, and each integer occurs exactly 5 times in the corresponding sequence. There is only one integer in the output file, which is the maximum number of matches for two DNA sequences. Sample Input2
1 1 2 2 1 1 2 1 2 2
1 2 2 2 1 1 2 2 1 1
Sample Output7
HINT

[Data constraints and scoring methods]
60% of the test data: 1<=n <= 1 000
100% of the test data: 1<=n <= 20 000

Source

Bzoj 1264: [AHOI2006] gene matching match (LCS)

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.