Description

给定两个字符串集合A,B,均包含N个字符串,长度均为M,求一个最短的区间[l,r],使得不存在字符串\(a\in A,b\in B,\)且\(a[l,r]=b[l,r]\) ,字符串只由ACGT组成,

\(n,m\leq500\)

Input Format

第一行包含N,M,

接下来N行,每行一个长度为M的字符串,描述集合A

最后N行,描述集合B

Output Format

一行表示最短区间的长度

Sample Input

3 8

AATCCCAT

ACTTGCAA

GGTCGCAA

ACTCCCAG

ACTCGCAT

ACTTCCAT

Sample Output

4

Solution

emmm,可以用字典树\(O(n^3)\)过,

枚举左端点,对于集合A每个字符串构造字典树,

然后查询集合B中每个字符串,更新答案即可

这里有个优化,即如果集合B中存在一个字符串在字典树中完全存在,直接break跳到下个左端点因为答案一定不存在

Code

#include <cstdio>
#include <algorithm>
#include <cstring>
#define N 550
using namespace std; int n,m,tr[N*N][5],Ans,cnt;
char s1[N][N],s2[N][N]; inline int opx(const char &c){
switch(c){
case 'A':return 1;break;
case 'C':return 2;break;
case 'G':return 3;break;
default:return 4;break;
}
} inline void add(const int &id,const int &l){
int now=0;
for(int i=l;i<m;++i){
int k=opx(s1[id][i]);
if(!tr[now][k]) tr[now][k]=++cnt;
now=tr[now][k];
}
} inline int Find(const int &id,const int &l){
int now=0;
for(int i=l;i<m;++i){
int k=opx(s2[id][i]);
if(!tr[now][k]) return i-l+1;
now=tr[now][k];
}
return -1;
} int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i) scanf("%s\n",s1[i]);
for(int i=1;i<=n;++i) scanf("%s\n",s2[i]);
Ans=1e9;
for(int l=0;l<m;++l){
cnt=0;
int mx=0;
memset(tr,0,sizeof(tr));
for(int i=1;i<=n;++i) add(i,l);
for(int i=1;i<=n;++i){
int len=Find(i,l);
if(len==-1){mx=1e9;break;}
mx=max(mx,len);
}
if(mx==1e9) break;
Ans=min(Ans,mx);
}
printf("%d\n",Ans);
return 0;
}

【NOIP模拟】【USACO】 Bovine Genomics的更多相关文章

  1. [USACO]Bovine Genomics

    Description 给定两个字符串集合A,B,均包含N个字符串,长度均为M,求一个最短的区间[l,r],使得不存在字符串\(a\in A,b\in B,\)且\(a[l,r]=b[l,r]\) , ...

  2. NOIP模拟赛20161022

    NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...

  3. contesthunter暑假NOIP模拟赛第一场题解

    contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...

  4. NOIP模拟赛 by hzwer

    2015年10月04日NOIP模拟赛 by hzwer    (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...

  5. 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程

    数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...

  6. 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...

  7. 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...

  8. 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...

  9. CH Round #58 - OrzCC杯noip模拟赛day2

    A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...

  10. CH Round #52 - Thinking Bear #1 (NOIP模拟赛)

    A.拆地毯 题目:http://www.contesthunter.org/contest/CH%20Round%20%2352%20-%20Thinking%20Bear%20%231%20(NOI ...

随机推荐

  1. iOS学习——如何在mac上获取开发使用的模拟器的资源以及模拟器中每个应用的应用沙盒

    如题,本文主要研究如何在mac上获取开发使用的模拟器的资源以及模拟器中每个应用的应用沙盒.做过安卓开发的小伙伴肯定很方便就能像打开资源管理器一样查看我们写到手机本地或应用中的各种资源,但是在iOS开发 ...

  2. CentOS7.2非HA分布式部署Openstack Pike版 (实验)

    部署环境 一.组网拓扑 二.设备配置 笔记本:联想L440处理器:i3-4000M 2.40GHz内存:12G虚拟机软件:VMware® Workstation 12 Pro(12.5.2 build ...

  3. CCF认证之——相反数

    这道题目非常简单! #include<iostream> using namespace std; int main() { ],n,count=; cin >> n; ; i ...

  4. JavaScript提高篇之面向对象之单利模式工厂模型构造函数原型链模式

    1.单例模式 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  5. Python中的单例模式

    在 Python 中,我们可以用多种方法来实现单例模式: 使用模块 使用 __new__ 使用装饰器(decorator) 使用元类(metaclass) # mysingleton.py class ...

  6. 16. 使用Exhibitor管理ZooKeeper

    Exhibitor是管理ZooKeeper服务实例的主管服务.由Netflix开发和开放源码,对于ZooKeeper的实例监控.备份/恢复.清理和可视化非常有用. Note Netflix Exhib ...

  7. 51Nod--1049最大子段和

    1049 最大子段和 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 N个整数组成的序列a[1],a[2],a[3],-,a[n],求该序列如a[i]+a ...

  8. zzuli 1815: easy problem 打表

    1815: easy problem Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 243  Solved: 108 SubmitStatusWeb ...

  9. 算法提高 9-3摩尔斯电码 map

    算法提高 9-3摩尔斯电码 时间限制:1.0s   内存限制:256.0MB     问题描述 摩尔斯电码破译.类似于乔林教材第213页的例6.5,要求输入摩尔斯码,返回英文.请不要使用"z ...

  10. mongo安装,及远程连接

    yum 安装mongo创建镜像 1 vi /etc/yum.repos.d/mongodb-org-3.6.repo添加一下路径 保存退出[mongodb-org-3.6]name=MongoDB R ...