【动态规划DP,二维动归】poj1080,Human Gene Functions
来源:互联网 发布:人工智能所用到的语言? 编辑:程序博客网 时间:2024/05/19 00:54
http://poj.org/problem?id=1080
注意,三种情况:
1)ai和bi匹配(不管a[i]和b[j]是否一样,因为不匹配也可以,只是代价为负而已!!!看代码注释掉的部分就知道什么意思了),
2)ai和空格匹配,再匹配ai-1和bj,
3)bj和空格匹配,再匹配ai和bj-1。
# include<iostream>using namespace std;# define N 103char a[N],b[N];int r[N][N];int match[N][N];void Init(){ match['A']['A']=match['C']['C']=match['G']['G']=match['T']['T']=5; match['A']['C']=match['C']['A']=match['A']['T']=match['T']['A']=match[' ']['T']=match['T'][' ']=-1; match['A']['G']=match['G']['A']=match['C']['T']=match['T']['C']=match['G']['T']=match['T']['G']=match['G'][' ']=match[' ']['G']=-2; match['A'][' ']=match[' ']['A']=match['C']['G']=match['G']['C']=-3; match['C'][' ']=match[' ']['C']=-4;}int main(){int t,i,j,k,l1,l2,t1,t2;Init();cin>>t;for(i=1;i<=t;i++){r[0][0]=0;cin>>l1;for(j=1;j<=l1;j++){cin>>a[j];r[j][0]=r[j-1][0]+match[a[j]][' '];}cin>>l2;for(k=1;k<=l2;k++){cin>>b[k];r[0][k]=r[0][k-1]+match[' '][b[k]];}for(j=1;j<=l1;j++){for(k=1;k<=l2;k++){/*if(a[j]==b[k]){r[j][k]=r[j-1][k-1]+match[a[j]][b[k]];}else{t1=r[j-1][k]+match[a[j]][' '];t2=r[j][k-1]+match[' '][b[k]];r[j][k] = t1>t2? t1:t2;}*/r[j][k]=r[j-1][k-1]+match[a[j]][b[k]];r[j][k]= r[j][k]>r[j-1][k]+match[a[j]][' ']? r[j][k]:r[j-1][k]+match[a[j]][' '];r[j][k]= r[j][k]>r[j][k-1]+match[' '][b[k]]? r[j][k]:r[j][k-1]+match[' '][b[k]];}}cout<<r[l1][l2]<<endl;}return 0;}
1 0
- 【动态规划DP,二维动归】poj1080,Human Gene Functions
- POJ1080 Human Gene Functions DP
- Human Gene Functions poj1080 dp
- POJ1080 Human Gene Functions 动态规划 LCS的变形
- poj1080--Human Gene Functions(dp:LCS变形)
- Human Gene Functions(POJ1080)
- poj1080 - Human Gene Functions
- POJ1080-Human Gene Functions
- POJ1080--Human Gene Functions
- poj1080 Human Gene Functions
- POJ1080 Human Gene Functions
- poj1080 Human Gene Functions
- 【POJ1080】【Human Gene Functions】
- POJ1080 Human Gene Functions
- poj1080 Human Gene Functions
- 【poj1080】 Human Gene Functions
- poj1080 Human Gene Functions
- 【POJ1080】Human Gene Functions(动态规划 最长公共子序列)
- linux shell通配符和正则表达式
- linux增加快捷键打开或关闭触摸板
- Genymotion安装配置
- oracle优化:避免全表扫描
- 使用EditText在不同场景下调用软键盘的总结
- 【动态规划DP,二维动归】poj1080,Human Gene Functions
- Appium for windows 环境安装搭建部署和第一个实例demo
- gcc编译器常识
- 第二部分 应用篇 第七章 MongoDB MapReduce
- AngularJS学习(九) $resource服务 前后台交互ajax
- 启动rabbitmq报错:/usr/lib/rabbitmq/bin/rabbitmq-server: line 80: /var/lib/rabbitmq/mnesia/rabbit@node2.p
- iPhone编程的一些小技巧
- android笔记
- 树结构(一) - 二叉树查找树的原理与实现