POJ 1080.Human Gene Functions
来源:互联网 发布:淘宝客链接转化工具 编辑:程序博客网 时间:2024/06/07 22:28
题目:http://poj.org/problem?id=1080
AC代码(C++):
#include <iostream>#include <algorithm>#include <stdio.h>#include <vector>#include <queue>#include <math.h>#include <string>#include <string.h>#include <bitset>#define INF 0xfffffff#define MAXN 100105using namespace std;int n,m;char str1[105];char str2[105];int dp[105][105];int score[100][100];int max3(int a, int b, int c){int tmp = a>b?a:b;return c>tmp?c:tmp;}int main(){int t;cin>>t;score['A']['A'] = 5;score['C']['C'] = 5;score['G']['G'] = 5;score['T']['T'] = 5;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;score['-']['-'] = -(INF);while(t--){cin>>n>>str1>>m>>str2;dp[0][0] = 0;for(int i = 1; i <= n; i++)dp[i][0] = dp[i-1][0] + score[str1[i-1]]['-'];for(int i = 1; i <= m; i++)dp[0][i] = dp[0][i-1] + score['-'][str2[i-1]];for(int i = 1; i <= n; i++){for(int j = 1; j <= m; j++){dp[i][j] = max3(dp[i-1][j-1]+score[str1[i-1]][str2[j-1]],dp[i-1][j] + score[str1[i-1]]['-'],dp[i][j-1] + score['-'][str2[j-1]]);}}cout<<dp[n][m]<<endl;}}总结: 动态规划, 最长公共子序列的变形. 这题的关键是在dp数组下移和右移的时候应该怎么加分数. 首先把行看做str1, 把列看做str2, 则下移代表在str2中插入-号来与str1匹配. 原因是如果下移的话, 则说明str1前进一步, 并且前进后与str2不匹配, 则需在str2中插入-号来与str1匹配. 右移同理.
如上图所示, 当dp从[4,5]下移到[5,5]时, 说明第5行的D与str2不匹配, 则往str2的BA(5列和6列)间插入-号来与之匹配. 右移也是一样的. 想通了这点之后这题就很简单了.
阅读全文
0 0
- POJ 1080.Human Gene Functions
- POJ 1080 Human Gene Functions
- POJ 1080 Human Gene Functions
- POJ 1080 Human Gene Functions
- poj 1080 Human Gene Functions
- POJ 1080 Human Gene Functions
- Poj 1080 Human Gene Functions
- poj 1080 Human Gene Functions
- poj 1080 Human Gene Functions
- POJ 1080 Human Gene Functions
- poj 1080 human gene functions
- POJ 1080 Human Gene Functions
- POJ 1080 Human Gene Functions
- POJ-1080-Human Gene Functions
- POJ 1080 Human Gene Functions
- POJ 1080 Human Gene Functions
- poj 1080 Human Gene Functions
- poj 1080 Human Gene Functions
- 线程池-浅析
- 搭建SVN服务器详细教程
- ScrollView中使用Listview,以及相关定位问题
- 队列-浅析
- 深度学习实践操作—从小白到大白(五):cuda & cudnn安装
- POJ 1080.Human Gene Functions
- JVM内存模型-浅析
- 【安全牛学习笔记】XSS-简介、跨站脚本检测和常见的攻击利用手段
- 快速排序
- 对于ssm过程中的乱码问题的处理
- 人类V.S.AI 无人机障碍赛对战人类获得一貹
- OpenStack-M版(Mitaka)搭建基于(Centos7.2)+++二、Openstack环境准备篇上
- 中缀表达式转换为后缀表达式-数据结构
- git client 配置以及连接GitHub、Bitbucket