[AHOI2006] gene matches match
Time Limit:10 Sec Memory limit:162 MB
submit:1240 solved:821
[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
http://blog.csdn.net/PoPoQQQ/article/details/39958251
1#include <cstdio>2#include <cstring>3#include <iostream>4#include <algorithm>5#include <cstdio>6 7 #defineM 2000078 using namespacestd;9InlineintRead ()Ten { One intx=0, f=1;CharCh=GetChar (); A while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} - while(ch>='0'&&ch<='9') {x= (x<<3) + (x<<1) +ch-'0'; ch=GetChar ();} - returnx*F; the } - - intN,ans; - inta[m*5],b[m*5],c[m*5],f[m*5],pos[m][6]; + - voidUpdate (intXinty) + { A for(; x<=n*5; x+=x&-x) atc[x]=Max (c[x],y); - } - intGet_ans (intx) - { - intRe=0; - for(; x;x-=x&-x) inRe=Max (re,c[x]); - returnre; to } + intMain () - { then=read (); * for(intI=1; i<=n*5; i++) $ {Panax Notoginsenga[i]=read (); -pos[a[i]][++pos[a[i]][0]]=i; the } + for(intI=1; i<=n*5; i++) b[i]=read (); A for(intI=1; i<=n*5; i++) the for(intj=5; j;j--) + { - intk=Pos[b[i]][j]; $F[k]=max (F[k],get_ans (K-1)+1); $ Update (K,f[k]); -ans=Max (ans,f[k]); - } theprintf"%d\n", ans); -}
Bzoj 1264 AHOI2006 gene matching match dynamic programming + Tree Array