博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SCOJ 4493: DNA 最长公共子串 后缀自动机
阅读量:5896 次
发布时间:2019-06-19

本文共 2575 字,大约阅读时间需要 8 分钟。

4493: DNA

题目连接:

Description

Deoxyribonucleic acid (DNA) is a molecule that carries most of the genetic instructions used in the development,

functioning and reproduction of all known living organisms and many viruses.
Most DNA molecules consist of two biopolymer strands coiled around each other to form a double helix.
The two DNA strands are known as polynucleotides since they are composed of simpler units called nucleotides.
Each nucleotide is composed of a nitrogen-containing nucleobase—either cytosine (C), guanine (G), adenine (A), or thymine (T)—
as well as a monosaccharide sugar called deoxyribose and a phosphate group. According to base pairing rules (A with T, and C with G),
hydrogen bonds bind the nitrogenous bases of the two separate polynucleotide strands to make double-stranded DNA.
We define the length of a strand as the number of its nucleobases. Given a bunch of different DNA strands, for each strand,
find the length of the longest common pieces between the two complementary strands.

Input

The first line is the number of test cases, T, where 0 < T<=100.

Each line followed represents a DNA strand, whose length is no more than 5000.

Output

For each strand, print a number, indicating the answer illustrated above.

Sample Input

3

A
AT
ATAT

Sample Output

0

1
3

Hint

题意

给你一个DNA序列,然后问他的互补串和他本身的最长公共子串是多少

题解:

后缀自动机/后缀数组/hash都可以过这道题

都是一个比较裸的题

下面代码是后缀自动机的

代码

#include
using namespace std;const int maxn = 5010;char s1[maxn], s2[maxn];struct SAM { struct { int len, f, ch[26]; void init() { len = 0, f = -1; memset(ch, 0xff, sizeof (ch)); } } e[maxn<<1]; int idx, last; void init() { idx = last = 0; e[idx++].init(); } int newnode() { e[idx].init(); return idx++; } void add(int c) { int end = newnode(); int tmp = last; e[end].len = e[last].len + 1; for (; tmp != -1 && e[tmp].ch[c] == -1; tmp = e[tmp].f) { e[tmp].ch[c] = end; } if (tmp == -1) e[end].f = 0; else { int nxt = e[tmp].ch[c]; if (e[tmp].len + 1 == e[nxt].len) e[end].f = nxt; else { int np = newnode(); e[np] = e[nxt]; e[np].len = e[tmp].len + 1; e[nxt].f = e[end].f = np; for (; tmp != -1 && e[tmp].ch[c] == nxt; tmp = e[tmp].f) { e[tmp].ch[c] = np; } } } last = end; }};SAM sam;void solve(){ scanf("%s",s1); int len = strlen(s1); for(int i=0;i

转载地址:http://yhxsx.baihongyu.com/

你可能感兴趣的文章
【模拟退火】poj1379 Run Away
查看>>
Windows安装JDK9
查看>>
Topology and Geometry in OpenCascade-Edge
查看>>
“玲珑杯”ACM比赛 Round #19
查看>>
Pandas 索引和选择数据(Indexing and Selecting Data)
查看>>
Openpyxl
查看>>
OvS: openflow param analysis
查看>>
windows下python虚拟环境vitrualenv与virtualenvwrapper安装
查看>>
每个设计师都应该知道的25个最好的CSS网页设计目录
查看>>
Git 实战手册(一): 批量修改log中的提交信息
查看>>
python3连接外部Mysql
查看>>
vue中对element-ui框架中el-table的列的每一项数据进行操作
查看>>
ubuntu修改源列表sourcelist的方法
查看>>
前端学PHP之文件操作
查看>>
leetcode 15: 三数之和(3sum)
查看>>
c 操作文件:实现关键词搜索
查看>>
distinct与order by
查看>>
[Java]JGit用法总结
查看>>
我要学算法
查看>>
判断 元素中是否有类
查看>>