嘟嘟嘟




这题怎么想都想不出来,最后还是敲了暴力,喜提40分……




正解竟然也是暴力……

用\(s_0\)构造SAM,然后把\(s\)扔上去暴力dfs:记录一个修改次数tot,如果当前不匹配,就tot + 1并且往下跳……

反正就是过了……

记得多组数据,清空数组。

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 1e5 + 5;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
} int n, m, ans = 0, val[200];
char s[maxn]; struct Sam
{
int las, cnt;
int tra[maxn << 1][5], len[maxn << 1], link[maxn << 1], siz[maxn << 1];
In void insert(int c)
{
int now = ++cnt, p = las;
len[now] = len[las] + 1; siz[now] = 1;
while(~p && !tra[p][c]) tra[p][c] = now, p = link[p];
if(p == -1) link[now] = 0;
else
{
int q = tra[p][c];
if(len[q] == len[p] + 1) link[now] = q;
else
{
int clo = ++cnt;
len[clo] = len[p] + 1;
memcpy(tra[clo], tra[q], sizeof(tra[q]));
link[clo] = link[q], link[q] = link[now] = clo;
while(~p && tra[p][c] == q) tra[p][c] = clo, p = link[p];
}
}
las = now;
}
int buc[maxn << 1], pos[maxn << 1];
In void sort()
{
for(int i = 1; i <= cnt; ++i) ++buc[len[i]];
for(int i = 1; i <= cnt; ++i) buc[i] += buc[i - 1];
for(int i = 1; i <= cnt; ++i) pos[buc[len[i]]--] = i;
for(int i = cnt; i; --i) siz[link[pos[i]]] += siz[pos[i]];
}
In void dfs(int p, int len, int tot)
{
if(tot > 3) return;
if(len >= m) {ans += siz[p]; return;}
for(int c = 1; c <= 4; ++c)
{
if(!tra[p][c]) continue;
if(c == val[s[len]]) dfs(tra[p][c], len + 1, tot);
else dfs(tra[p][c], len + 1, tot + 1);
}
}
In void init()
{
Mem(tra, 0), Mem(link, 0), Mem(len, 0), Mem(siz, 0);
link[las = cnt = 0] = -1;
Mem(buc, 0), Mem(pos, 0);
}
}S; int main()
{
val['A'] = 1, val['T'] = 2, val['G'] = 3, val['C'] = 4;
int T = read();
while(T--)
{
S.init(); ans = 0;
scanf("%s", s); n = strlen(s);
for(int i = 0; i < n; ++i) S.insert(val[s[i]]);
S.sort();
scanf("%s", s); m = strlen(s);
S.dfs(0, 0, 0);
write(ans), enter;
}
return 0;
}

[TJOI2017]DNA的更多相关文章

  1. bzoj4892 [TJOI2017]DNA

    bzoj4892 [TJOI2017]DNA 给定一个匹配串和一个模式串,求模式串有多少个连续子串能够修改不超过 \(3\) 个字符变成匹配串 \(len\leq10^5\) hash 枚举子串左端点 ...

  2. [TJOI2017]DNA --- 后缀数组

    [TJOI2017]DNA 题目描述 加里敦大学的生物研究所,发现了决定人喜不喜欢吃藕的基因序列S, 有这个序列的碱基序列就会表现出喜欢吃藕的性状,但是研究人员发现对碱基序列S,任意修改其中不超过3个 ...

  3. [洛谷P3763] [TJOI2017]DNA

    洛谷题目链接:[TJOI2017]DNA 题目描述 加里敦大学的生物研究所,发现了决定人喜不喜欢吃藕的基因序列S,有这个序列的碱基序列就会表现出喜欢吃藕的性状,但是研究人员发现对碱基序列S,任意修改其 ...

  4. [TJOI2017] DNA - 后缀数组,稀疏表

    [TJOI2017] DNA Description 求模式串与主串的匹配次数,容错不超过三个字符. Solution 枚举每个开始位置,进行暴力匹配,直到失配次数用光或者匹配成功.考虑到容错量很小, ...

  5. BZOJ4892:[TJOI2017]dna(hash)

    Description 加里敦大学的生物研究所,发现了决定人喜不喜欢吃藕的基因序列S,有这个序列的碱基序列就会表现出喜欢吃藕的性状,但是研究人员发现对碱基序列S,任意修改其中不超过3个碱基,依然能够表 ...

  6. [BZOJ4892][TJOI2017]DNA(后缀数组)

    题目描述 加里敦大学的生物研究所,发现了决定人喜不喜欢吃藕的基因序列S,有这个序列的碱基序列就会表现出喜欢吃藕的性状,但是研究人员发现对碱基序列S,任意修改其中不超过3个碱基,依然能够表现出吃藕的性状 ...

  7. 洛谷3763:[TJOI2017]DNA——题解

    https://www.luogu.org/problemnew/show/P3763 加里敦大学的生物研究所,发现了决定人喜不喜欢吃藕的基因序列S,有这个序列的碱基序列就会表现出喜欢吃藕的性状,但是 ...

  8. Luogu3763 TJOI2017 DNA NTT/SA

    传送门 两种做法: ①SA 将两个串拼在一次建立后缀数组,把\(height\)数组求出来,然后对于\(S\)中每一个长度为\(T\)的串和\(T\)暴力匹配,每一次找到最长的\(LCP\)匹配,如果 ...

  9. P3763 [TJOI2017]DNA

    链接:https://www.luogu.org/problemnew/show/P3763 题解: 挺水的一题后缀数组 枚举每一个开头用后缀数组判断能否在3次内匹配完

随机推荐

  1. bash array

    bash 仅支持一维数组. 而且数组下标是从0开始的为数组赋值:array=(1 4 7 2 5 8)     #以空格为分割符,()为数组str="this is test string& ...

  2. JavaScript是如何工作的:Service Worker的生命周期及使用场景

    摘要: 理解Service Worker. 原文:JavaScript 是如何工作的:Service Worker 的生命周期及使用场景 作者:前端小智 Fundebug经授权转载,版权归原作者所有. ...

  3. 使用typeof()或者typeof数据类型检测

    使用typeof()或者typeof进行基本数据类型检测(  typeof(X)等于typeof X  返回的是数据类型) 数据类型有:基本数据类型,字符串(string),布尔值(true/fals ...

  4. 【linux】如何开放防火墙端口

    linux默认大部分端口的是关闭的.而我们在开发.部署环境时,需要用到大量的服务,如mysql.tomcat.redis.zk等,需要开放指定的端口号. 以mysql端口3306为例 首先编辑服务器的 ...

  5. 微信wx.request

    官方 wx.request 代码,Post 没成功过,使用Get 方式成功了. wx.request({ url: 'test.php', //仅为示例,并非真实的接口地址 data: { x: '' ...

  6. 获取邮箱的DNS和MX 工具类

    1.导入Maven  DNS  包: <dependency> <groupId>dnsjava</groupId> <artifactId>dnsja ...

  7. 2018-10-04 [日常]用Python读取word文档中的表格并比较

    最近想对某些word文档(docx)的表格内容作比较, 于是找了一下相关工具. 参考Automate the Boring Stuff with Python中的word部分, 试用了python-d ...

  8. [vue三部曲]第一部:vue脚手架的搭建和目录资源介绍,超详细!

    第一步 node环境安装 1.1 如果本机没有安装node运行环境,请下载node 安装包进行安装1.2 如果本机已经安装node的运行换,请更新至最新的node 版本下载地址:https://nod ...

  9. SAP FI配置步骤

    http://blog.sina.com.cn/s/blog_8eda1a620100uwzj.html No. 配置对象 事务代码 配置内容 路径 备注 1 定义公司 OX15 企业结构>定义 ...

  10. Android assets文件夹之位置放置和作用

    Android 的assets文件夹的放置位置,Eclipse创建项目时就生成了的,Android Studio则不太一样,AS可以包含几种方式, 1:可以在build.gradle文件下配置,加如下 ...