简单广搜。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. 运行第一个SparkKPI程序

    1.复制一个examples中SparkPi.scala到IntelliJ IDEA编辑器,运行,出现错误: “org.apache.spark.SparkException: A master UR ...

  2. mapreduce 依赖组合

    mport java.io.IOException;import java.util.StringTokenizer; import org.apache.hadoop.conf.Configurat ...

  3. android 界面悬浮框实现

    // 定义浮动窗口布局 private View mFloatLayout; // 定义浮动窗口布局对象 private WindowManager.LayoutParams wmParams; // ...

  4. Lightoj 1004 - Monkey Banana Problem

    题目链接:http://acm.hust.edu.cn/vjudge/contest/121396#problem/F http://lightoj.com/volume_showproblem.ph ...

  5. linux下执行scrapy的爬虫定时任务

    刚开始执行scrapy crawl zentaos可以完成扫描 但是通过linux的crontab任务,只执行了连接mongodb的操作,并创建了索引 也就是说scrapy crawl zentaos ...

  6. ping命令使用技巧(一次Ping多个地址)

    打开windows 命令行 窗口, 在命令行输入以下命令: for /l %i in (1,1,255) do ping -n 1  -w 60 192.168.0.%i  | find " ...

  7. getWritableDatabase()与getReadableDatabase()的区别:

    getWritableDatabase取得的实例不是仅仅具有写的功能,而是同时具有读和写的功能同样的 getReadableDatabase取得的实例也是具对数据库进行读和写的功能. 两者的区别在于 ...

  8. xdebug 安装

    如果是这样的话,请参考 http://www.mengyunzhi.com/share/php/107-xdebug.html 进行xdebug的安装.

  9. 自定义solr的search UI

    solr使用apache的velocity来定义UI,在solr的search ui的基础上更改即可,主要改\example\solr\collection1\conf\velocity里的文件. 详 ...

  10. ie用document.getElementsByName获取不到

    document.getElementsByName('someName') 返回一个节点列表(数组) 注意:在IE下有些节点是没有name 属性的,就是用document.getElementsBy ...