POJ1080 Human Gene Functions(LCS)
题目链接。
分析:
和 LCS 差不多。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map> using namespace std; const int maxn = ; int G[][] = {
{, -, -, -, -},
{-, , -, -, -},
{-, -, , -, -},
{-, -, -, , -},
{-, -, -, -, }
}; int dp[maxn][maxn]; void trans(char *s, int n) {
for(int i=; i<n; i++) {
switch(s[i]) {
case 'A': s[i] = ; break;
case 'C': s[i] = ; break;
case 'G': s[i] = ; break;
case 'T': s[i] = ; break;
case '-': s[i] = ; break;
}
}
} int main(){
int T, n, m;
// freopen("my.txt", "r", stdin);
char s1[maxn], s2[maxn]; scanf("%d", &T); while(T--) {
scanf("%d%s%d%s", &n, s1, &m, s2);
trans(s1, n); trans(s2, m); dp[][] = ;
for(int i=; i<=m; i++) dp[i][] = G[s2[i-]][] + dp[i-][]; for(int i=; i<=n; i++) dp[][i] = G[s1[i-]][] + dp[][i-]; for(int i=; i<=m; i++) {
for(int j=; j<=n; j++) {
int u = s2[i-], v = s1[j-]; dp[i][j] = dp[i-][j-] + G[u][v];
dp[i][j] = max(dp[i][j], dp[i-][j]+G[u][]);
dp[i][j] = max(dp[i][j], dp[i][j-]+G[v][]);
}
} printf("%d\n", dp[m][n]);
} return ;
}
POJ1080 Human Gene Functions(LCS)的更多相关文章
- POJ 1080:Human Gene Functions LCS经典DP
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18007 Accepted: ...
- poj1080 - Human Gene Functions (dp)
题面 It is well known that a human gene can be considered as a sequence, consisting of four nucleotide ...
- POJ1080 Human Gene Functions 动态规划 LCS的变形
题意读了半年,唉,给你两串字符,然后长度不同,你能够用'-'把它们补成同样长度,补在哪里取决于得分,它会给你一个得分表,问你最大得分 跟LCS非常像的DP数组 dp[i][j]表示第一个字符串取第i个 ...
- poj 1080 Human Gene Functions(lcs,较难)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19573 Accepted: ...
- hdu1080 Human Gene Functions() 2016-05-24 14:43 65人阅读 评论(0) 收藏
Human Gene Functions Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- Human Gene Functions
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18053 Accepted: 1004 ...
- poj 1080 ——Human Gene Functions——————【最长公共子序列变型题】
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17805 Accepted: ...
- 【POJ 1080】 Human Gene Functions
[POJ 1080] Human Gene Functions 相似于最长公共子序列的做法 dp[i][j]表示 str1[i]相应str2[j]时的最大得分 转移方程为 dp[i][j]=max(d ...
- 刷题总结——Human Gene Functions(hdu1080)
题目: Problem Description It is well known that a human gene can be considered as a sequence, consisti ...
随机推荐
- CSS 有趣的边框
今天看到一篇文章.是利用CSS边框来做折纸效果.感觉非常有意思.于是就对CSS的border研究了一下.发现还真有一些好玩的使用方法. 1.border折纸效果 首先是HTML代码,为了简单,就一个d ...
- Android中为图标加上数字--用于未读短信数提醒,待更新应用数提醒等
本文属于原创,转载请著名出处:http://flysnow.iteye.com/blog/906770 写道 在我们开发一些如短消息.应用商店等应用时,会考虑在短消息的图标上加上未读短信的数量,在应用 ...
- Git和Github的应用与命令方法总结
title: Git和Github的应用与命令方法总结 date: 2016-07-11 14:03:09 tags: git/github [本文摘抄自微信公众平台:AndroidDeveloper ...
- JSON 解析(门店)
package com.j1.mai.action; import java.io.BufferedReader; import java.io.IOException; import java.io ...
- python-列表、字典、元组的员工信息处理接口(第二篇(五):基于列表、字典和元组的员工信息处理接口)
Python之旅]第二篇(五):基于列表.字典和元组的员工信息处理接口 python 列表 字典 元组 员工信息处理接口 摘要: 1.基本需求 编写一个查询员工信息表的程序,实现如下功能: ( ...
- AJAX入门学习(转)
一.基础概念 1.全称:Asynchronous.JavaScript.And.XML(异步的 JavaScript 和 XML). 2.定义: Ajax不是一个技术,它实际上是几种技术,每种技术都有 ...
- C#简单邮件发送
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); message.From = new System.N ...
- 自签名SSL生成
本教程以AppServ生成自签名证书为例,同时配置OpenSSL环境1.生成自签名证书,控制台程序进入Apache目录下的bin目录 >openssl req -config ../conf/o ...
- Linq101-Set
using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class Set { / ...
- JS 改变input 输入框样式
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...