日韩性视频-久久久蜜桃-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自动机+矩阵快速幂)的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 久操伊人网| 就去色av| 国产av自拍一区 | 国产伊人自拍 | 成人在线短视频 | 男女互操| 麻豆精品网站 | 三级小说视频 | 日韩高清中文字幕 | 中文字幕乱码人妻一区二区三区 | 久久免费黄色 | www.天天射 | 人妻aⅴ无码一区二区三区 阿v免费视频 | 夜夜高潮夜夜爽国产伦精品 | 欧美特黄一级视频 | 欧美一区二区三区婷婷月色 | 久久精品aaaaaa毛片 | 精品国产乱码久久久久久婷婷 | 色老大网站 | 婷婷色在线播放 | 天天操网址 | 国产精品传媒一区二区 | 日韩欧美123 | 国产精品中文在线 | 一级黄色片免费在线观看 | 日本黄页网址 | 久久色网站 | www.色国产 | 国产日本欧美在线 | 91喷水视频 | 人人爽夜夜爽 | 中国毛片在线观看 | 欧美福利片在线观看 | 亚洲在线观看一区 | 在线观看国产免费视频 | 欧美黑人疯狂性受xxxxx野外 | 久久亚洲一区二区 | 日本做爰三级床戏 | 久久尤物视频 | 国产精品麻豆成人av电影艾秋 | 国产91嫩草 | 日韩不卡毛片 | 国产精品性爱在线 | 日韩和欧美一区二区 | 四虎影视免费在线观看 | 男女www视频| 亚洲淫片 | 91视频a| 日韩激情中文字幕 | 午夜福利123 | 91伦理 | 乱人伦xxxx国语对白 | 欧美成人一二三区 | 久久久久久久久91 | 毛片网站在线播放 | 国产午夜视频在线观看 | 欧美爱爱小视频 | 伊人视屏 | 伊人二区 | av片免费| 国产精品一区二区免费视频 | 精品国产三级 | 波多野结衣黄色网址 | 亚洲三区在线观看无套内射 | 神马久久香蕉 | 光棍影院手机版在线观看免费 | 天天操夜夜干 | 中文字幕精品三级久久久 | 另类激情视频 | 少妇的性事hd | 亚洲手机在线观看 | 国产一区二区三区视频播放 | 午夜毛片在线 | 婷婷综合激情 | 亚洲激情图片 | 日本欧美国产在线 | 经典三级第一页 | 国产极品美女高潮无套嗷嗷叫酒店 | 成人福利影院 | 欧美美女一级片 | 中国女人毛片 | www.黄色.| 青青草免费在线观看 | 亚洲高清视频一区二区 | av美女在线 | 欧美手机在线 | 午夜99 | 热99精品视频 | 综合激情视频 | 一区二区三区国 | 久久免费看 | 网站毛片 | 性感美女黄色片 | 欧美一区二不卡视频 | 超碰最新上传 | 美女被草网站 | 亚洲青春草 | 久久天天躁狠狠躁夜夜av | 免费大片黄在线观看视频网站 |