HUST 1605 Gene recombination
简单广搜。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的更多相关文章
- hust 1605 - Gene recombination(bfs+字典树)
1605 - Gene recombination Time Limit: 2s Memory Limit: 64MB Submissions: 264 Solved: 46 DESCRIPTION ...
- HUST 1605 Gene recombination(广搜,位运算)
题目描述 As a gene engineer of a gene engineering project, Enigma encountered a puzzle about gene recomb ...
- hust 1605 bfs
思路:直接用优先队列优化bfs. #include<map> #include<queue> #include<vector> #include<cmath& ...
- HUST 1017 - Exact cover (Dancing Links 模板题)
1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 5584 次提交 2975 次通过 题目描述 There is an N*M matrix with only 0 ...
- 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 ...
- 合并基因表达水平(merge gene expression levels, FPKM)
使用tophat和cufflinks计算RNA-seq数据的表达水平时,当一个基因在一个样本中有多个表达水平时需要合并它们的表达水平. This code is a solution to colla ...
- augustus, gene prediction, trainning
做基因组注释 先用augustus训练,然后再用maker做基因注释 augustus提供一些训练好的,如果有和你的物种非常接近的,直接用提供的,没有的话再自己训练. 网址: http://bioin ...
- ubuntu 16.04 source (HUST and 163)
#HUST deb http://mirrors.hust.edu.cn/ubuntu/ xenial main restricted universe multiverse deb http://m ...
- Dancing Link --- 模板题 HUST 1017 - Exact cover
1017 - Exact cover Problem's Link: http://acm.hust.edu.cn/problem/show/1017 Mean: 给定一个由0-1组成的矩阵,是否 ...
随机推荐
- php 10.1总
在做添加时写是否已经有该文件 $_sql1 = "SELECT * FROM tb_user where userName = {$_clean['userName']} "; $ ...
- HttpServletResponse对象
Web服务器收到客户端的http请求,会针对每一次请求,分别创建一个用于代表请求的request对象.和代表响应的response对象. request和response对象即然代表请求和响应,那我们 ...
- HDU 2579/BFS/ Dating with girls(2)
题目链接 /* 题意是是传统的迷宫加上一个条件,墙壁在k的整倍数时刻会消失,那么求到达出口的最短时间. 关键点在于某个点最多被走k次,标记vis[x][y][time%k]即可. */ #includ ...
- cddiv/数组维护
题目连接 看代码: #include <set> #include <map> #include <cmath> #include <queue> #i ...
- 《JavaScript高级程序设计》读书笔记 ---变量
ECMAScript 的变量是松散类型的,所谓松散类型就是可以用来保存任何类型的数据.换句话说,每个变量仅仅是一个用于保存值的占位符而已.定义变量时要使用var 操作符(注意var 是一个关键字),后 ...
- 【转】HBase技术介绍 转载自 http://www.searchtb.com/2011/01/understanding-hbase.html
HBase简介 HBase – Hadoop Database,是一个高可靠性.高性能.面向列.可伸缩的分布式存储系统,利用HBase技术可在廉价PC Server上搭建起大规模结构化存储集群. HB ...
- UVALive 2523 Machine Schedule(二分图求最大匹配数)
题意:有两台机器,上面有多个工作区域,有多个任务,分别可以在两台机器的某一个区域上完成,两台机器一开始都在0区域上工作,每次更改区域,都会重新启动一次,让我们求出最小的重启次数. 思路:将两个区域连线 ...
- Kth order statistcs
Selection: selection is a trivial problem if the input numbers are sorted. If we use a sorting algor ...
- android - 自定义(组合)控件 + 自定义控件外观
转载:http://www.cnblogs.com/bill-joy/archive/2012/04/26/2471831.html android - 自定义(组合)控件 + 自定义控件外观 A ...
- jquery选中checkbox多选项并添加到文本框中
<script> function check(){ var dd = ""; if($("input[type='checkbox'][name='moke ...