• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            poj3691

            DNA repair


            Time Limit: 2000MS
            Memory Limit: 65536K
            Total Submissions: 4281
            Accepted: 1985

            Description

            Biologists finally invent techniques of repairing DNA that contains segments causing kinds of inherited diseases. For the sake of simplicity, a DNA is represented as a string containing characters 'A', 'G' , 'C' and 'T'. The repairing techniques are simply to change some characters to eliminate all segments causing diseases. For example, we can repair a DNA "AAGCAG" to "AGGCAC" to eliminate the initial causing disease segments "AAG", "AGC" and "CAG" by changing two characters. Note that the repaired DNA can still contain only characters 'A', 'G', 'C' and 'T'.

            You are to help the biologists to repair a DNA by changing least number of characters.

            Input

            The input consists of multiple test cases. Each test case starts with a line containing one integers N (1 ≤ N ≤ 50), which is the number of DNA segments causing inherited diseases.
            The following N lines gives N non-empty strings of length not greater than 20 containing only characters in "AGCT", which are the DNA segments causing inherited disease.
            The last line of the test case is a non-empty string of length not greater than 1000 containing only characters in "AGCT", which is the DNA to be repaired.

            The last test case is followed by a line containing one zeros.

            Output

            For each test case, print a line containing the test case number( beginning with 1) followed by the
            number of characters which need to be changed. If it's impossible to repair the given DNA, print -1.

            Sample Input

            2 AAA AAG AAAG     2 A TG TGAATG 4 A G C T AGT 0

            Sample Output

            Case 1: 1 Case 2: 4 Case 3: -1

            Source

            2008 Asia Hefei Regional Contest Online by USTC


            有個(gè)題解寫(xiě)的挺好的
            看這里

            http://www.cnblogs.com/woodfish1988/archive/2008/10/03/1303492.html

            就是用trie圖來(lái)表示狀態(tài)及狀態(tài)之間的轉(zhuǎn)移

            code
            #include <cstdio>
            #include 
            <cstdlib>
            #include 
            <cstring>
            #include 
            <cmath>
            #include 
            <ctime>
            #include 
            <cassert>
            #include 
            <iostream>
            #include 
            <sstream>
            #include 
            <fstream>
            #include 
            <map>
            #include 
            <set>
            #include 
            <vector>
            #include 
            <queue>
            #include 
            <algorithm>
            #include 
            <iomanip>
            #define maxn 1105
            #define inf 0x7fffffff
            using namespace std;
            struct node
            {
                
            int next[4];
                
            int fail,count;
                
            void init()
                {
                    memset(next,
            -1,sizeof(next));
                    fail
            =-1;
                    count
            =0;
                }
            } s[maxn];
            int f[maxn][maxn];
            int hash[256];
            int sind,times,n;
            int q[maxn],head,tail;
            void cas_init()
            {
                s[
            0].init();
                sind
            =1;
            }
            void ins(char str[])
            {
                
            int i,j,len,ind;
                len
            =strlen(str);
                ind
            =0;
                
            for(i=0; i<len; i++)
                {
                    j
            =hash[str[i]];
                    
            if(s[ind].next[j]==-1)
                    {
                        s[sind].init();
                        s[ind].next[j]
            =sind++;
                    }
                    ind
            =s[ind].next[j];
                }
                s[ind].count
            ++;
            }
            void make_fail()
            {
                
            int u,i,p,son;
                head
            =0;
                tail
            =1;
                q[tail]
            =0;
                
            while(head<tail)
                {
                    head
            ++;
                    u
            =q[head];
                    
            for(i=0; i<4; i++)
                    {
                        
            if(s[u].next[i]!=-1)
                        {
                            p
            =s[u].fail;
                            son
            =s[u].next[i];
                            
            while(p!=-1&&s[p].next[i]==-1) p=s[p].fail;
                            
            if(u==0) s[son].fail=0;
                            
            else s[son].fail=s[p].next[i];
                            
            if(s[s[son].fail].count) s[son].count=1;
                            q[
            ++tail]=son;
                        }
                        
            else
                        {
                            p
            =s[u].fail;
                            
            while(p!=-1&&s[p].next[i]==-1)
                                p
            =s[p].fail;
                            
            if(u==0) s[u].next[i]=0;
                            
            else  s[u].next[i]=s[p].next[i];
                        }
                    }
                }
            }
            int min(int a,int b)
            {
                
            if(a==-1return b;
                
            if(b==-1return a;
                
            return a<b?a:b;
            }
            void getans(char str[])
            {
                
            int v,i,j,k;
                
            int ans=inf;
                
            int len;
                len
            =strlen(str);
                memset(f,
            -1,sizeof(f));
                f[
            0][0]=0;
                
            for(i=1; i<=len; i++)
                {
                    
            for(j=0; j<sind; j++)
                        
            if(f[i-1][j]!=-1)
                        {
                            
            for(k=0; k<4; k++)
                            {
                                v
            =s[j].next[k];
                                
            if(s[v].count==0)
                                {
                                    f[i][v]
            =min(f[i][v],f[i-1][j]+(k!=hash[str[i-1]]));
                                }
                            }
                        }
                }
                
            //printf("%d\n",i);
                ans=-1;
                
            for(i=0; i<sind; i++)
                {
                    
            if(s[i].count==0)
                    {
                        ans
            =min(ans,f[len][i]);
                    }
                }
                printf(
            "Case %d: %d\n",++times,ans);
            }
            int main()
            {
                
            char str[50],str1[1005];
                hash[
            'A']=0;
                hash[
            'T']=1;
                hash[
            'G']=2;
                hash[
            'C']=3;
                times
            =0;
                
            while(scanf("%d",&n)!=EOF&&n!=0)
                {
                   
            // printf("%d\n",n);
                    cas_init();
                    
            for(int i=1; i<=n; i++)
                    {
                        scanf(
            "%s",str);
                        ins(str);
                    }
                    make_fail();
                    scanf(
            "%s",str1);
                    getans(str1);
                }
                
            return 0;
            }

            posted on 2012-07-30 21:40 jh818012 閱讀(169) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評(píng)論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當(dāng)于是 取余3的意思 因?yàn)?3 的 二進(jìn)制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄](méi)
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
            • --王私江
            国内精品伊人久久久影院| 无码日韩人妻精品久久蜜桃| 国产精品美女久久久| 亚洲成色999久久网站| 久久久中文字幕日本| 久久受www免费人成_看片中文 | 狠色狠色狠狠色综合久久| 久久亚洲天堂| 久久国产精品一区二区| 久久无码AV中文出轨人妻| 91精品国产高清91久久久久久| 国产精品免费看久久久香蕉| 久久久久亚洲AV成人网人人网站 | 亚洲成人精品久久| 久久久久99这里有精品10 | 久久综合久久综合久久综合| 久久久午夜精品福利内容| 久久久久久狠狠丁香| 热99RE久久精品这里都是精品免费| 97精品伊人久久大香线蕉app | 99久久精品毛片免费播放| 久久综合九色欧美综合狠狠| 久久91精品国产91久久小草 | 99久久夜色精品国产网站| 亚洲中文字幕无码久久精品1| 国产成人香蕉久久久久| 久久国产热精品波多野结衣AV| 一本一道久久a久久精品综合| 爱做久久久久久| 99精品久久久久久久婷婷| AV色综合久久天堂AV色综合在| 久久久无码精品亚洲日韩蜜臀浪潮 | 青青草国产97免久久费观看| 伊人久久大香线蕉av不变影院| 久久综合欧美成人| 天天久久狠狠色综合| 久久精品人人做人人爽97| 久久66热人妻偷产精品9| 97超级碰碰碰久久久久| 日本久久久久久中文字幕| 久久九九青青国产精品|