简单广搜。4进制对应的10进制数来表示这些状态,总共只有(4^12)种状态。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<algorithm>
using namespace std; const int maxn = ;
bool m[];
struct P
{
int state;
int tot;
};
queue<P>Q;
char s1[maxn], s2[maxn];
int tmp1[maxn], r1, tmp2[maxn], r2;
int A, B;
int n;
int b[maxn]; int f(char sign)
{
if (sign == 'A') return ;
if (sign == 'T') return ;
if (sign == 'G') return ;
if (sign == 'C') return ;
} void init()
{
while (!Q.empty()) Q.pop();
memset(m, , sizeof m); A = B = ;
for (int i = ; s1[i]; i++) A = A + f(s1[i])*b[i];
for (int i = ; s2[i]; i++) B = B + f(s2[i])*b[i];
} void BFS()
{
P now; now.state = A; now.tot = ; m[A] = ; Q.push(now);
while (!Q.empty())
{
P head = Q.front(); Q.pop();
if (head.state == B)
{
printf("%d\n", head.tot);
break;
} memset(tmp1, , sizeof tmp1);
memset(tmp2, , sizeof tmp2); r2 = r1 = ; int w = head.state;
while (w) tmp2[r2++] = tmp1[r1++] = w % , w = w / ; swap(tmp1[], tmp1[]);
int new_state = ;
for (int i = ; i < n; i++) new_state = new_state + tmp1[i] * b[i]; if (m[new_state] == )
{
m[new_state] = ;
P d; d.state = new_state; d.tot = head.tot + ;
Q.push(d);
} new_state = ;
tmp2[n] = tmp2[];
for (int i = ; i <= n; i++) new_state = new_state + tmp2[i] * b[i - ]; if (m[new_state] == )
{
m[new_state] = ;
P d; d.state = new_state; d.tot = head.tot + ;
Q.push(d);
}
}
} int main()
{
b[] = ; for (int i = ; i <= ; i++) b[i] = * b[i - ]; while (~scanf("%d", &n))
{
scanf("%s%s", s1, s2);
init();
BFS();
}
return ;
}

HUST 1605 Gene recombination的更多相关文章

  1. hust 1605 - Gene recombination(bfs+字典树)

    1605 - Gene recombination Time Limit: 2s Memory Limit: 64MB Submissions: 264 Solved: 46 DESCRIPTION ...

  2. HUST 1605 Gene recombination(广搜,位运算)

    题目描述 As a gene engineer of a gene engineering project, Enigma encountered a puzzle about gene recomb ...

  3. hust 1605 bfs

    思路:直接用优先队列优化bfs. #include<map> #include<queue> #include<vector> #include<cmath& ...

  4. HUST 1017 - Exact cover (Dancing Links 模板题)

    1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 5584 次提交 2975 次通过 题目描述 There is an N*M matrix with only 0 ...

  5. KEGG and Gene Ontology Mapping in Bioinformatic Method

    使用KOBAS进行KEGG pathway和Gene Ontology分析 Article from Blog of Alfred-Feng http://blog.sina.com.cn/u/170 ...

  6. 合并基因表达水平(merge gene expression levels, FPKM)

    使用tophat和cufflinks计算RNA-seq数据的表达水平时,当一个基因在一个样本中有多个表达水平时需要合并它们的表达水平. This code is a solution to colla ...

  7. augustus, gene prediction, trainning

    做基因组注释 先用augustus训练,然后再用maker做基因注释 augustus提供一些训练好的,如果有和你的物种非常接近的,直接用提供的,没有的话再自己训练. 网址: http://bioin ...

  8. ubuntu 16.04 source (HUST and 163)

    #HUST deb http://mirrors.hust.edu.cn/ubuntu/ xenial main restricted universe multiverse deb http://m ...

  9. Dancing Link --- 模板题 HUST 1017 - Exact cover

    1017 - Exact cover Problem's Link:   http://acm.hust.edu.cn/problem/show/1017 Mean: 给定一个由0-1组成的矩阵,是否 ...

随机推荐

  1. 【转】ethtool 命令详解

    命令描述: ethtool 是用于查询及设置网卡参数的命令. 使用概要:ethtool ethx       //查询ethx网口基本设置,其中 x 是对应网卡的编号,如eth0.eth1等等etht ...

  2. RatingBar

    题记:保持旺盛的求知欲.希望会一直这样. 说明:来了新控件了.就是经常用的打分的那种东东. 说明:1.看上图分别是系统自带的和自己做的.rating就是设置小星星的数目. 2.用系统自带的必须是Wra ...

  3. AI 人工智能 探索 (五)

    我们把做好的 角色 拖到 内存池,如图所示,这样我们可以动态生成角色并给予他 寻路目标. //逗留碰撞 void OnTriggerStay(Collider other) { if (other.t ...

  4. useradd adduer 的区别

    区别 1). 使用useradd时,如果后面不添加任何参数选项,例如:#sudo useradd test创建出来的用户将是默认“三无”用户:一无Home Directory,二无密码,三无系统She ...

  5. hdu Eddy's picture (最小生成树)

    Eddy's picture Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tota ...

  6. 使用Github搭建个人博客网站

    1 新建一个repo,创建一个没有父节点的分支gh-pages(github规定,只有该分支中的页面,才会生成网页文件): mkdir jekyll_demo cd jekyll_demo git i ...

  7. IDL 计算TVDI

    介绍请看:http://blog.sina.com.cn/s/blog_764b1e9d0100wdrr.html 源码: IDL 源码PRO TVDI,NDVI,LST,NBINS,RES RES ...

  8. Nodejs开源项目里怎么样写测试、CI和代码测试覆盖率

    测试 目前主流的就bdd和tdd,自己查一下差异 推荐 mocha和tape 另外Jasmine也挺有名,angularjs用它,不过挺麻烦的,还有一个选择是qunit,最初是为jquery测试写的, ...

  9. acm的第一场比赛的总结

    6.4-6.5号很激动的去湖南湘潭打了一场邀请赛,这是第一次acm的旅程吧.毕竟大一上册刚开始接触c,然后现在就能抱着学长的大腿(拖着学长的后腿)打比赛,也是有一点小小的激动. 第一天很早就起床了,由 ...

  10. activemq学习

    一.特性及优势 1.实现JMS1.1规范,支持J2EE1.4以上2.可运行于任何jvm和大部分web容器(ActiveMQ works great in any JVM)3.支持多种语言客户端(jav ...