Hdu2144evolution (and check set + violence or LCS)

Source: Internet
Author: User

EvolutionTime limit:20000/5000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 598 Accepted Submission (s): 143


Problem Description every kind of living creatures has a kind of DNA. The nucleotide bases from which DNA was built is A (adenine), C (cytosine), G (guanine), and T (thymine). Sometimes if the DNA of the living creatures has the same substring, and the length is beyond a certain percentage of the Whole length, we many consider whether the living creatures have the same ancestor. And we can separate them into a certain species temporarily for our we, and we say the both living creatures are simi Lar Make sure if A are similar with B, and B are similar with C, but C was not similar with A, we also separate A, B and C in To a kind, for during the evolution, there happens aberrance.
Now we have some kinds of living creatures and their DNA, just tell us how many kinds of living creatures we can separate.

Input There is a lot of cases. In each case, the first line there is numbers n and P. N means the number of kinds of living creatures. If the DNA is similar, there exist a substring, and its length was beyond the percentage of any DNA of the the, and P is J UST the percentage. and 1<=n<=100, and 1<=p<100 (P is, which means-similar if and only if they was the same, so we Make sure P is smaller than 100). The length of each DNA won ' t exceed 100.

Output for each case, just print how many kinds living creatures we can separate.

Sample Input
3 10.0AAAAACCC

Sample Output
Case 1:2
#include <stdio.h> #include <string.h>const int N = 105;int fath[n],ins[n],n;void init () {for (int i=0;i<n; i++) fath[i]=i,ins[i]=0;}    int Findfath (int x) {if (x!=fath[x]) Fath[x]=findfath (fath[x]); return fath[x];}    void Setfath (int x,int y) {x=findfath (x);    Y=findfath (y); Fath[x]=y;}    int main () {double P;    int c=0,len[n];    Char Dna[n][n];             while (scanf ("%d%lf", &n,&p) >0) {for (int i=0;i<n;i++) {scanf ("%s", Dna[i]);        Len[i]=strlen (Dna[i]);        } init ();            for (int i=0, i<n; i++) for (int j=i+1; j<n; J + +) {int maxlen=0,flag=0; for (int ti=0;ti<len[i]&&maxlen<len[i]-ti;ti++) {for (int tj=0;tj<len[j]&&am                    p;maxlen<len[j]-tj;tj++) {int ii,jj; for (II=TI,JJ=TJ; ii<len[i]&&jj<len[j]; ii++,jj++) if (dna[i][ii]!=dNA[J][JJ]) {break;                    } if (Ii-ti>maxlen) Maxlen=ii-ti;                    if (100*maxlen/(len[i]*1.0) >p&&100* (maxlen/(len[j]*1.0)) >p) Setfath (i,j), flag=1;                if (flag) break;            } if (flag) break;        }} int k=0;        for (int i=0;i<n;i++) if (fath[i]==i) k++;    printf ("Case%d:\n%d\n", ++c,k); }}


Hdu2144evolution (and check set + violence or 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.