zoukankan      html  css  js  c++  java
  • csu 1242 碱基配对——一个错误的解答

    早上刚看了如何用 dp 解决LCS,想到了这道题,无奈这道题和LCS不同,还要求对应位置匹配。

    还是遇到了一个小问题:序列是从1开始的,但是数组的下标是从0开始的,于是想到了gets(a+1)这样的方法,这时要对a[0]赋以非 0 初值

    /* csu 1242 错误:非LCS问题*/
    # include <stdio.h>
    # include <string.h>

    # define MAXN 1002

    char a[MAXN], b[MAXN];
    short c[MAXN][MAXN];

    short int solve(void)
    {
    short ans, m, n, i, j, tmp;

    memset(c, 0, sizeof(c));

    m = strlen(a)-1, n = strlen(b)-1;

    for (i = 1; i <= m; ++i)
    for (j = 1; j <= n; ++j)
    {
    tmp = a[i]+b[j];
    if (tmp==('A'+'T') || tmp==('C'+'G'))
    c[i][j] = 1 + c[i-1][j-1];
    else c[i][j] = (c[i-1][j]>=c[i][j-1] ? c[i-1][j]:c[i][j-1]);
    }

    return c[m][n];
    }

    int main()
    {
    a[0] = b[0] = '1';
    while (gets(a+1) != NULL)
    {
    gets(b+1);
    printf("%d\n", solve());
    }
    return 0;
    }



  • 相关阅读:
    python note 30 断点续传
    python note 29 线程创建
    python note 28 socketserver
    python note 27 粘包
    python note 26 socket
    python note 25 约束
    Sed 用法
    python note 24 反射
    python note 23 组合
    python note 22 面向对象成员
  • 原文地址:https://www.cnblogs.com/JMDWQ/p/2387427.html
Copyright © 2011-2022 走看看