"BZOJ1264" [AHOI2006] gene matches match dp+ tree array

Source: Internet
Author: User

"BZOJ1264" [AHOI2006] gene matching matchdescription gene matching (match) Kaka dreamed last night that he and cocoa had come to another planet, and that the DNA sequence of the planet's creatures was made up of countless bases (only 4 species on Earth), And even more strangely, each of the bases that make up the DNA sequence appears 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 from 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

Puzzle: The process of recalling the longest common sub-sequence, the transfer matrix difference is actually a 01 matrix, we will 1 as a two-bit plane of a pile of points, and then become a path up to the maximum number of points. Because of the special nature of the subject, the number of points =25n, so the tree-like array.

#include <cstdio> #include <cstring> #include <iostream>using namespace Std;const int Maxn=100010;int N;int a[maxn],b[maxn],p[maxn][7],s[maxn];inline void Updata (int x,int val) {for (int i=x;i<=5*n;i+=i&-i) s[i]= Max (s[i],val);} inline int query (int x) {int i,ret=0;for (i=x;i;i-=i&-i) Ret=max (Ret,s[i]); return ret;} inline Int rd () {int Ret=0,f=1;char gc=getchar (); while (gc< ' 0 ' | | Gc> ' 9 ') {if (gc== '-') F=-f;gc=getchar ();} while (gc>= ' 0 ' &&gc<= ' 9 ') ret=ret*10+gc-' 0 ', Gc=getchar (); return ret*f;} int main () {int i,j,v;n=rd (); for (i=1;i<=5*n;i++) v=rd (), P[v][++p[v][0]]=i;for (i=1;i<=5*n;i++) {v=rd (); for (j=5 ; j>=1;j--) Updata (P[v][j],query (p[v][j]-1) +1);} printf ("%d", query (5*n)); return 0;}

"BZOJ1264" [AHOI2006] gene matches match dp+ tree array

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.