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组成的矩阵,是否 ...
随机推荐
- .bash_profile和.bashrc的什么区别
/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置./etc/bashrc:为每一个运 ...
- jquery 控制文本输入的字数
<textarea maxlength="200" id="remarks" onkeyup="title_len();">&l ...
- [转]JSONObject与JSONArray的使用
http://www.cnblogs.com/xwdreamer/archive/2011/12/16/2296904.html 参考文献: http://blog.csdn.net/huangwuy ...
- HDU 1054 Strategic Game(树形DP)
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- The Accumulation of Capital
The Accumulation of Capital ---- by *Adam Smith Capitals are increased by parsimony, and diminished ...
- cisco 密码重置
密码重置 分类: 转贴技术资料 2007-12-28 16:38 http://www.cisco.com/en/US/products/hw/routers/ps259/products_passw ...
- USB的八个问题和答案(转)
http://www.amobbs.com/thread-901041-1-1.html 问题一:USB的传输线结构是如何的呢? 答案一:一条USB的传输线分别由地线.电源线.D+.D-四条线构成,D ...
- 用JavaScript 来将数字转换成字符。
背景: 一切嵌入式设备上面的信息,比如设备名称,设备时区是可以写入到设备上面的寄存器中的(一个寄存器两个字节,2*8 bit),比如 -1 ,写入到寄存器中为 2d31,然后可以通过一些进程将寄存器中 ...
- 1.2 selenium IDE录制脚本
1.打开Firefox浏览器中 selenium IDE
- Tree of Life (easy)
Tree of Life (easy) Heidi has finally found the mythical Tree of Life – a legendary combinatorial st ...