HUST 1605 Gene recombination

Posted Fighting Heart

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 = 15;
map<int, int>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 0;
    if (sign == T) return 1;
    if (sign == G) return 2;
    if (sign == C) return 3;
}

void init()
{
    while (!Q.empty()) Q.pop();
    m.clear(); A = B = 0;
    for (int i = 0; s1[i]; i++) A = A + f(s1[i])*b[i];
    for (int i = 0; s2[i]; i++) B = B + f(s2[i])*b[i];
}

void BFS()
{
    P now; now.state = A; now.tot = 0; m[A] = 1; Q.push(now);
    while (!Q.empty())
    {
        P head = Q.front(); Q.pop();
        if (head.state == B)
        {
            printf("%d\n", head.tot);
            break;
        }

        memset(tmp1, 0, sizeof tmp1);
        memset(tmp2, 0, sizeof tmp2);

        r2 = r1 = 0; int w = head.state;
        while (w) tmp2[r2++] = tmp1[r1++] = w % 4, w = w / 4;

        swap(tmp1[0], tmp1[1]);
        int new_state = 0;
        for (int i = 0; i < n; i++) new_state = new_state + tmp1[i] * b[i];

        if (m[new_state] == 0)
        {
            m[new_state] = 1;
            P d; d.state = new_state; d.tot = head.tot + 1;
            Q.push(d);
        }

        new_state = 0;
        tmp2[n] = tmp2[0];
        for (int i = 1; i <= n; i++) new_state = new_state + tmp2[i] * b[i - 1];

        if (m[new_state] == 0)
        {
            m[new_state] = 1;
            P d; d.state = new_state; d.tot = head.tot + 1;
            Q.push(d);
        }
    }
}

int main()
{
    b[0] = 1; for (int i = 1; i <= 11; i++) b[i] = 4 * b[i - 1];
    
    while (~scanf("%d", &n))
    {
        scanf("%s%s", s1, s2);
        init();
        BFS();
    }
    return 0;
}

 

以上是关于HUST 1605 Gene recombination的主要内容,如果未能解决你的问题,请参考以下文章

Gene Ontology

如何将上百个gene symbol 转换成gene ID

从列表到数据框查找基因名称

直系同源基因(orthologous gene)和旁系同源基因(paralogous gene)

gene ID转换(gene ID转为protein ID) pathway注释 string数据库的方法

GO(Gene Ontology)