zoukankan      html  css  js  c++  java
  • poj 1080

    http://poj.org/problem?id=1080

    知识点 :最长公共子序列

    要点:

    转移方程  f[i][j]  = max{ f[i-i][j]+score[s1[i-1]]['-'],  f[i][j-1]+score['-'][s2[j-1]],  f[i-1][j-1]+score[s1[i-1]][s2[j-1]]}

    #include <iostream>
    
    using namespace std;
    int score['T'+1]['T'+1];
    int dp[1000][1000];
    char s1[200],s2[200];
    void init(){
        score['A']['A']=5;
        score['C']['C'] =5;
        score['G']['G'] =5;
        score['T']['T'] =5;
        score['-']['-'] = -10;
        score['A']['C'] = score['C']['A']=-1;
        score['A']['G'] = score['G']['A']=-2;
        score['A']['T'] = score['T']['A']=-1;
        score['A']['-'] = score['-']['A']=-3;
        score['C']['G'] = score['G']['C']=-3;
        score['C']['T'] = score['T']['C']=-2;
        score['C']['-'] = score['-']['C']=-4;
        score['G']['T'] = score['T']['G']=-2;
        score['G']['-'] = score['-']['G']=-2;
        score['T']['-'] = score['-']['T']=-1;
    }
    
    int mx(int a,int b,int c){
        int k = a>b?a:b;
        return c>k?c:k;
    }
    int main()
    {
        init();
        int t;
        cin>>t;
        while(t--){
            int len1,len2;
            cin>>len1>>s1>>len2>>s2;
            dp[0][0] =0;
            for(int i=1;i<=len1;i++){
                dp[i][0] = dp[i-1][0]+score[s1[i-1]]['-'];
            }
            for(int j=1;j<=len2;j++){
                dp[0][j] = dp[0][j-1]+score['-'][s2[j-1]];
            }
            for(int i=1;i<=len1;i++){
                for(int j=1;j<=len2;j++){
                    int temp1 = dp[i-1][j]+score[s1[i-1]]['-'];
                    int temp2 = dp[i][j-1]+score['-'][s2[j-1]];
                    int temp3 = dp[i-1][j-1]+score[s1[i-1]][s2[j-1]];
                    dp[i][j] = mx(temp1,temp2,temp3);
                }
            }
            cout<<dp[len1][len2]<<endl;
        }
        return 0;
    }
  • 相关阅读:
    jQury+Ajax与C#后台交换数据
    loadrunner 测试问题汇总
    Loadrunner脚本学习总结
    sar命令详解
    用sar进行CPU利用率的分析
    centos7-sar工具的安装过程及其简单应用
    shell if [ -d filename]
    shell脚本自带变量的含义
    Sublime Text2使用规则
    selenium grid结构图
  • 原文地址:https://www.cnblogs.com/Bang-cansee/p/3236318.html
Copyright © 2011-2022 走看看