Hdu2144 evolution (LCS + and query set)

Source: Internet
Author: User

Given the gene sequence of N species, if the longest common substring lengths of the two sequences S1 and S2 meet the requirements of | S1 | * P <Len & | S2 | * P <Len (P indicates the percentage given by the question ), the two species belong to the same category.

Analysis: Count, LCs + and query set

View code

# Include <iostream> # Include <Algorithm> # Include < String > # Include <Vector> Using   Namespace  STD;  Const   Int N = 100 +10  ;  Int  N, F [N];  Double  P;  Char  STR [N] [N];  Void  Init (){  For ( Int I = 0 ; I <n; I ++ ) F [I] = I ;}  Int Find (Int  X ){  If (X = F [x])  Return  F [X]; F [x] = Find (F [x]);  Return  F [X];}  Int LCS ( Const   Char * Str1, Const   Char * Str2 ){ Int Xlen = strlen (str1 ); //  Horizontal length      Int TMP [N] = { 0 }; //  Save the previous row of the matrix      Int Arr [N] = { 0 }; //  Current row      Int Ylen = strlen (str2 ); //  Vertical length      Int Maxele = 0 ; //  Maximum value in a matrix element      Int Pos = 0 ; //  Maximum number of Matrix Elements in Column      For ( Int I = 0 ; I <xlen; I ++ ){  For ( Int J = 0 ; J <ylen; j ++ ) {Arr [J] = 0  ;  If (Str1 [I] = Str2 [J]) {  If (J = 0  ) Arr [J] = 1  ;  Else  Arr [J] = TMP [J- 1 ] + 1  ;  If (ARR [J]> Maxele) {maxele = Arr [J]; POS = J ;}}}  For ( Int J = 0 ; J <ylen; j ++ ) TMP [J] = Arr [J];}  Return Maxele ;}  Int  Main (){  Int CAS = 0  ;  While (Scanf ( "  % D % lf  " , & N, & P) = 2  ) {Init ();  For ( Int I = 0 ; I <n; I ++) Scanf (  "  % S  "  , STR [I]);  For ( Int I = 0 ; I <n; I ++ ){  Int A = Find (I );  Int Len1 = Strlen (STR [I]);  For (Int J = I + 1 ; J <n; j ++ ){  Int B = Find (j );  If (A = B) //  If you already belong to the same class, you do not need to ask for it.                      Continue  ;  Int Len = LCS (STR [I], STR [J]);  Int Len2 =Strlen (STR [J]);  If (Len1 * p * 0.01 <Len & len2 * p * 0.01 < Len) f [B] = A ;}}  Int Ans = 0  ;  For ( Int I = 0 ; I <n; I ++ ){ If (I = Find (I) ans ++ ;} Printf (  "  Case % d: \ n % d \ n  " , ++ CAS, ANS );}  Return   0  ;} 

 

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.