HDU 1080 Human Gene Functions(LCS变形)

Human Gene Functions

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2661    Accepted Submission(s): 1504


Problem Description
It is well known that a human gene can be considered as a sequence, consisting of four nucleotides, which are simply denoted by four letters, A, C, G, and T. Biologists have been interested in identifying human genes and determining their functions, because these can be used to diagnose human diseases and to design new drugs for them. 

A human gene can be identified through a series of time-consuming biological experiments, often with the help of computer programs. Once a sequence of a gene is obtained, the next job is to determine its function. One of the methods for biologists to use in determining the function of a new gene sequence that they have just identified is to search a database with the new gene as a query. The database to be searched stores many gene sequences and their functions – many researchers have been submitting their genes and functions to the database and the database is freely accessible through the Internet. 

A database search will return a list of gene sequences from the database that are similar to the query gene. Biologists assume that sequence similarity often implies functional similarity. So, the function of the new gene might be one of the functions that the genes from the list have. To exactly determine which one is the right one another series of biological experiments will be needed. 

Your job is to make a program that compares two genes and determines their similarity as explained below. Your program may be used as a part of the database search if you can provide an efficient one. 

Given two genes AGTGATG and GTTAG, how similar are they? One of the methods to measure the similarity of two genes is called alignment. In an alignment, spaces are inserted, if necessary, in appropriate positions of the genes to make them equally long and score the resulting genes according to a scoring matrix. 

For example, one space is inserted into AGTGATG to result in AGTGAT-G, and three spaces are inserted into GTTAG to result in –GT--TAG. A space is denoted by a minus sign (-). The two genes are now of equal length. These two strings are aligned: 

AGTGAT-G 
-GT--TAG 

In this alignment, there are four matches, namely, G in the second position, T in the third, T in the sixth, and G in the eighth. Each pair of aligned characters is assigned a score according to the following scoring matrix.

* denotes that a space-space match is not allowed. The score of the alignment above is (-3)+5+5+(-2)+(-3)+5+(-3)+5=9. 

Of course, many other alignments are possible. One is shown below (a different number of spaces are inserted into different positions): 

AGTGATG 
-GTTA-G 

This alignment gives a score of (-3)+5+5+(-2)+5+(-1) +5=14. So, this one is better than the previous one. As a matter of fact, this one is optimal since no other alignment can have a higher score. So, it is said that the similarity of the two genes is 14.
 

Input
The input consists of T test cases. The number of test cases ) (T is given in the first line of the input. Each test case consists of two lines: each line contains an integer, the length of a gene, followed by a gene sequence. The length of each gene sequence is at least one and does not exceed 100. 
 

Output
The output should print the similarity of each test case, one per line. 
 

Sample Input
  
2 7 AGTGATG 5 GTTAG 7 AGCTATT 9 AGCTTTAAA
 

Sample Output
  
14 21
 

Source
 

Recommend
We have carefully selected several similar problems for you:   1074  1227  1224  1160  1501 
 

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)
typedef long long ll;
#define bug printf("hi\n")
#define INF 0x3f3f3f3f
#define N 100005

using namespace std;

#define N 105

int va[N*5][N*5];
char a[N],b[N];
int lena,lenb;
int dp[N][N];

void inint()
{
    va['A']['A']=5;
    va['A']['C']=-1;
    va['A']['G']=-2;
    va['A']['T']=-1;
    va['A']['-']=-3;

    va['C']['A']=-1;
    va['C']['C']=5;
    va['C']['G']=-3;
    va['C']['T']=-2;
    va['C']['-']=-4;

    va['G']['A']=-2;
    va['G']['C']=-3;
    va['G']['G']=5;
    va['G']['T']=-2;
    va['G']['-']=-2;

    va['T']['A']=-1;
    va['T']['C']=-2;
    va['T']['G']=-2;
    va['T']['T']=5;
    va['T']['-']=-1;

    va['-']['A']=-3;
    va['-']['C']=-4;
    va['-']['G']=-2;
    va['-']['T']=-1;
    va['-']['-']=-INF;
}

void DP()
{
    int i,j;
    for(i=0;i<=lena;i++)
        for(j=0;j<=lenb;j++)
          dp[i][j]=-INF;

    dp[0][0]=0;
    dp[1][0]=va[a[1]]['-'];
    dp[0][1]=va['-'][b[1]];
    for(i=1;i<=lena;i++)
       dp[i][0]=dp[i-1][0]+va[a[i]]['-'];
    for(i=1;i<=lenb;i++)
        dp[0][i]=dp[0][i-1]+va['-'][b[i]];

    for(i=1;i<=lena;i++)
        for(j=1;j<=lenb;j++)
       {
          dp[i][j]=dp[i-1][j-1]+va[a[i]][b[j]];
          dp[i][j]=max(dp[i][j],dp[i-1][j]+va[a[i]]['-']);
          dp[i][j]=max(dp[i][j],dp[i][j-1]+va['-'][b[j]]);
       }
     printf("%d\n",dp[lena][lenb]);
}

int main()
{
    int i,j,t;
    inint();

    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%s",&lena,a+1);
        scanf("%d%s",&lenb,b+1);
        DP();
    }
    return 0;
}




根据原作 https://pan.quark.cn/s/459657bcfd45 的源码改编 Classic-ML-Methods-Algo 引言 建立这个项目,是为了梳理和总结传统机器学习(Machine Learning)方法(methods)或者算法(algo),和各位同仁相互学习交流. 现在的深度学习本质上来自于传统的神经网络模型,很大程度上是传统机器学习的延续,同时也在不少时候需要结合传统方法来实现. 任何机器学习方法基本的流程结构都是通用的;使用的评价方法也基本通用;使用的一些数学知识也是通用的. 本文在梳理传统机器学习方法算法的同时也会顺便补充这些流程,数学上的知识以供参考. 机器学习 机器学习是人工智能(Artificial Intelligence)的一个分支,也是实现人工智能最重要的手段.区别于传统的基于规则(rule-based)的算法,机器学习可以从数据中获取知识,从而实现规定的任务[Ian Goodfellow and Yoshua Bengio and Aaron Courville的Deep Learning].这些知识可以分为四种: 总结(summarization) 预测(prediction) 估计(estimation) 假想验证(hypothesis testing) 机器学习主要关心的是预测[Varian在Big Data : New Tricks for Econometrics],预测的可以是连续性的输出变量,分类,聚类或者物品之间的有趣关联. 机器学习分类 根据数据配置(setting,是否有标签,可以是连续的也可以是离散的)和任务目标,我们可以将机器学习方法分为四种: 无监督(unsupervised) 训练数据没有给定...
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值