日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

poj2778DNA Sequence (AC自动机+矩阵快速幂)

發布時間:2025/3/15 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 poj2778DNA Sequence (AC自动机+矩阵快速幂) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

轉載請注明出處:?http://www.cnblogs.com/fraud/?????????? ——by fraud

?

DNA Sequence
Time Limit: 1000MS?Memory Limit: 65536K

Description

It's well known that DNA Sequence is a sequence only contains A, C, T and G, and it's very useful to analyze a segment of DNA Sequence,For example, if a animal's DNA sequence contains segment ATC then it may mean that the animal may have a genetic disease. Until now scientists have found several those segments, the problem is how many kinds of DNA sequences of a species don't contain those segments.

Suppose that DNA sequences of a species is a sequence that consist of A, C, T and G,and the length of sequences is a given integer n.

Input

First line contains two integer m (0 <= m <= 10), n (1 <= n <=2000000000). Here, m is the number of genetic disease segment, and n is the length of sequences.

Next m lines each line contain a DNA genetic disease segment, and length of these segments is not larger than 10.

Output

An integer, the number of DNA sequences, mod 100000.

Sample Input

4 3 AT AC AG AA

Sample Output

36

Source

POJ Monthly--2006.03.26,dodo 題意 構造一個長度為n的DNA序列,要求其中不得出現m個禁止的字符串中的任意一個 一道很明顯的矩陣快速冪的題。先通過AC自動機得出一個鄰接矩陣,然后快速冪。 1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 #include <queue> 5 using namespace std; 6 #define REP(A,X) for(int A=0;A<X;A++) 7 #define MAXN 100010 8 9 int p[MAXN][4]; 10 int tail[MAXN]; 11 int fail[MAXN]; 12 int root,tot; 13 const long long MOD =100000; 14 struct Matrix{ 15 int n; 16 int mat[110][110]; 17 Matrix(){} 18 Matrix(int _n){ 19 n=_n; 20 REP(i,n) 21 REP(j,n)mat[i][j]=0; 22 } 23 void init() 24 { 25 REP(i,tot) 26 REP(j,tot)mat[i][j]=0; 27 } 28 void unit() 29 { 30 REP(i,tot) 31 REP(j,tot)mat[i][j]=i==j?1:0; 32 } 33 Matrix operator *(const Matrix &a)const { 34 Matrix ret(n); 35 REP(i,n) 36 REP(j,n) 37 REP(k,n) 38 { 39 int tmp=(long long)mat[i][k]*a.mat[k][j]%MOD; 40 ret.mat[i][j]=(ret.mat[i][j]+tmp)%MOD; 41 } 42 return ret; 43 } 44 }; 45 int newnode() 46 { 47 REP(i,4)p[tot][i]=-1; 48 tail[tot++]=0; 49 return tot-1; 50 } 51 void init() 52 { 53 tot=0; 54 root=newnode(); 55 } 56 int a[MAXN]; 57 void insert(char *s){ 58 int len=strlen(s); 59 REP(i,len) 60 { 61 if(s[i]=='A')a[i]=0; 62 else if(s[i]=='C')a[i]=1; 63 else if(s[i]=='G')a[i]=2; 64 else if(s[i]=='T')a[i]=3; 65 } 66 int now= root ; 67 REP(i,len) 68 { 69 if(p[now][a[i]]==-1)p[now][a[i]]=newnode(); 70 now=p[now][a[i]]; 71 } 72 tail[now]++; 73 } 74 void build() 75 { 76 int now=root; 77 queue<int >q; 78 fail[root]=root; 79 REP(i,4){ 80 if(p[root][i]==-1){ 81 p[root][i]=root; 82 } 83 else { 84 fail[p[root][i]]=root; 85 q.push(p[root][i]); 86 } 87 } 88 while(!q.empty()) 89 { 90 now =q.front(); 91 q.pop(); 92 if(tail[fail[now]])tail[now]=1; 93 REP(i,4){ 94 if(p[now][i]==-1){ 95 p[now][i]=p[fail[now]][i]; 96 }else{ 97 fail[p[now][i]]=p[fail[now]][i]; 98 q.push(p[now][i]); 99 } 100 } 101 } 102 } 103 char s[MAXN]; 104 Matrix Mat; 105 int main() 106 { 107 ios::sync_with_stdio(false); 108 int n,m; 109 while(cin>>m>>n){ 110 init(); 111 REP(i,m){ 112 cin>>s; 113 insert(s); 114 } 115 build(); 116 Mat.n=tot; 117 Mat.init(); 118 REP(i,tot){ 119 REP(j,4){ 120 if(!tail[p[i][j]])Mat.mat[i][p[i][j]]++; 121 } 122 } 123 Matrix tmp(tot); 124 tmp.unit(); 125 while(n){ 126 if(n&1)tmp=tmp*Mat; 127 Mat=Mat*Mat; 128 n>>=1; 129 } 130 int ans=0; 131 REP(i,tot)ans+=tmp.mat[0][i]; 132 ans%=MOD; 133 cout<<ans<<endl; 134 135 } 136 return 0; 137 } 代碼君

轉載于:https://www.cnblogs.com/fraud/p/4338491.html

新人創作打卡挑戰賽發博客就能抽獎!定制產品紅包拿不停!

總結

以上是生活随笔為你收集整理的poj2778DNA Sequence (AC自动机+矩阵快速幂)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 日韩精品tv| 中文字幕乱码中文乱码b站 国产一区二区三区在线观看视频 | 久久天天躁狠狠躁夜夜av | 人妖性做爰aaaa | 亚洲在线看片 | 亚洲精品在线影院 | 亚洲图片欧美 | 老熟妇毛片 | 88av在线| 欧美性一区二区 | 国产精品美女高潮无套 | 久久亚洲一区二区三区四区 | 色中文网 | 91久色蝌蚪 | 成人中文字幕在线观看 | 亚洲精品国产精品国自产观看浪潮 | 午夜免费毛片 | 深夜影院在线观看 | 亚洲第一精品在线 | 国产精品入口久久 | 亚洲天堂五月 | 三级视频在线观看 | av导航在线| 日韩欧美视频免费在线观看 | 最新日韩av在线 | 婷婷色激情 | 成人片黄网站色大片免费毛片 | 午夜痒痒网 | 黄色一级视频免费 | 欧美一区二区三区在线观看 | 男女交性视频播放 | 国产精品欧美在线 | 操操综合 | 99爱精品视频 | 日韩av福利 | 成人av网址在线 | 咪咪色在线视频 | 无码人妻一区二区三区免费n鬼沢 | 99久久精品国产成人一区二区 | 亚洲性色视频 | 天天干天天干天天干 | 色悠悠网 | 精品国产一区二区三区久久久久久 | 欧美日韩一二三四 | 国产精品二区在线观看 | 97伊人| 情侣作爱视频网站 | 蜜臀av性久久久久蜜臀aⅴ四虎 | 97视频网址 | 91午夜剧场 | 蜜臀av午夜精品 | www中文在线| 精品女同一区 | 91久久久久一区二区 | 日本精品视频在线 | 亚洲天堂五月 | www.av网站| 风间由美在线视频 | 日韩3区 | 粉嫩aⅴ一区二区三区 | 久久人成| 亚洲av无一区二区三区怡春院 | 娇小萝被两个黑人用半米长 | 青青草成人在线观看 | av在线播放一区二区三区 | 在线观看麻豆 | 瑟瑟在线观看 | 亚洲国产精品成人综合色在线婷婷 | zjzjzjzjzj亚洲女人 | 日本视频免费在线 | 五月婷婷,六月丁香 | 黑丝一区二区三区 | 色人天堂 | 高潮喷水一区二区三区 | 五月天国产视频 | av资源在线播放 | 草草屁屁影院 | 日本无遮挡边做边爱边摸 | 熟女毛毛多熟妇人妻aⅴ在线毛片 | 婷婷四房播播 | 白嫩日本少妇做爰 | 国产xxxx做受性欧美88 | 91九色蝌蚪在线 | 免费在线黄色av | 亚洲免费国产视频 | 日本高清在线播放 | av制服丝袜在线 | 国产成人毛毛毛片 | 国产成人av网站 | 亚洲精品一区二区三区四区 | 国产手机精品视频 | 九九小视频 | 国产精品15p | 国产成人一区二区三区免费看 | 欧美五月婷婷 | 久久久久二区 | 99视频网 | 日韩精品在线观看一区 | 精品一区二区三区在线免费观看 |