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'+]['T'+];
int dp[][];
char s1[],s2[];
void init(){
score['A']['A']=;
score['C']['C'] =;
score['G']['G'] =;
score['T']['T'] =;
score['-']['-'] = -;
score['A']['C'] = score['C']['A']=-;
score['A']['G'] = score['G']['A']=-;
score['A']['T'] = score['T']['A']=-;
score['A']['-'] = score['-']['A']=-;
score['C']['G'] = score['G']['C']=-;
score['C']['T'] = score['T']['C']=-;
score['C']['-'] = score['-']['C']=-;
score['G']['T'] = score['T']['G']=-;
score['G']['-'] = score['-']['G']=-;
score['T']['-'] = score['-']['T']=-;
} 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[][] =;
for(int i=;i<=len1;i++){
dp[i][] = dp[i-][]+score[s1[i-]]['-'];
}
for(int j=;j<=len2;j++){
dp[][j] = dp[][j-]+score['-'][s2[j-]];
}
for(int i=;i<=len1;i++){
for(int j=;j<=len2;j++){
int temp1 = dp[i-][j]+score[s1[i-]]['-'];
int temp2 = dp[i][j-]+score['-'][s2[j-]];
int temp3 = dp[i-][j-]+score[s1[i-]][s2[j-]];
dp[i][j] = mx(temp1,temp2,temp3);
}
}
cout<<dp[len1][len2]<<endl;
}
return ;
}
poj 1080的更多相关文章
- poj 1080 zoj 1027(最长公共子序列变种)
http://poj.org/problem?id=1080 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=27 /* zoj ...
- 【POJ 1080】 Human Gene Functions
[POJ 1080] Human Gene Functions 相似于最长公共子序列的做法 dp[i][j]表示 str1[i]相应str2[j]时的最大得分 转移方程为 dp[i][j]=max(d ...
- poj 1080 Human Gene Functions(dp)
题目:http://poj.org/problem?id=1080 题意:比较两个基因序列,测定它们的相似度,将两个基因排成直线,如果需要的话插入空格,使基因的长度相等,然后根据那个表格计算出相似度. ...
- POJ 1080 Human Gene Functions -- 动态规划(最长公共子序列)
题目地址:http://poj.org/problem?id=1080 Description It is well known that a human gene can be considered ...
- poj 1080 dp如同LCS问题
题目链接:http://poj.org/problem?id=1080 #include<cstdio> #include<cstring> #include<algor ...
- dp poj 1080 Human Gene Functions
题目链接: http://poj.org/problem?id=1080 题目大意: 给两个由A.C.T.G四个字符组成的字符串,可以在两串中加入-,使得两串长度相等. 每两个字符匹配时都有个值,求怎 ...
- POJ 1080( LCS变形)
题目链接: http://poj.org/problem?id=1080 Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K ...
- POJ - 1080 枚举 / DP
要求max{F/P},先枚举下界lowf,再贪心求符合约束条件的n个最小价值和 记录F的离散值和去重可以大幅度常数优化 (本来想着用DP做的) (辣鸡POJ连auto都Complie Error) # ...
- poj 1080 (LCS变形)
Human Gene Functions 题意: LCS: 设dp[i][j]为前i,j的最长公共序列长度: dp[i][j] = dp[i-1][j-1]+1;(a[i] == b[j]) dp[i ...
随机推荐
- Gartner 认定 Microsoft 为具有远见卓识的云基础结构即服务提供商
四个月前, Windows Azure 基础结构服务结束了预览版阶段,正式发布了,它具有业内领先的 SLA.随后, 凭借愿景的完整性和执行力,Gartner 很快认可了 Microsoft 在市场中的 ...
- Codeforces 700A As Fast As Possible(二分答案)
[题目链接] http://codeforces.com/problemset/problem/700/A [题目大意] 有一辆限载k人速度为v2的车,n个步行速度均为v1的人要通过一段长度为l的距离 ...
- Home | eMine: Web Page Transcoding Based on Eye Tracking Project Page
Home | eMine: Web Page Transcoding Based on Eye Tracking Project Page The World Wide Web (web) has m ...
- ListView中响应item的点击事件并且刷新界面
---恢复内容开始--- 最近在在实现listview功能中遇到了这个问题: 点击事件写在了adapter的item中,不知道如何在listview的点击事件中更新数据的显示: 总结:1.要使用not ...
- SQL基础常用语法
一.基础 1.说明:创建数据库 CREATE DATABASE database-name 2.说明:删除数据库 DROP database dbname 3.说明:创建新表 create table ...
- 使用wininet向FTP服务器发送文件
.h #pragma once #include <windows.h> #include <tchar.h> #include <string> #include ...
- PHP-购物网站开发设计(二)
2015-07-7 今天介绍购物网站的后台数据库设计,数据库使用的是MySQL (1)在MySQL数据库中新建Database,命名为test (2)在test下新建三个数据表,分别为mismatch ...
- ORA-02396: exceeded maximum idle time, please connect again的原因
一般为了防止过多活动的session占用资源,可以对允许连接到数据库的session个数,已连接到数据库的session空闲时间等进行限制(当然也可以对尝试连接次数等其它很多内容进行限制).方式就是可 ...
- [LeetCode]题解(python):132-Palindrome Partitioning II
题目来源: https://leetcode.com/problems/palindrome-partitioning-ii/ 题意分析: 给定一个s,可以将s拆成若干个回文子字符串之和,如果拆成了m ...
- 通过读取excel数据和mysql数据库数据做对比(二)-代码编写测试
通过上一步,环境已搭建好了. 下面开始实战, 首先,编写链接mysql的函数conn_sql.py import pymysql def sql_conn(u,pwd,h,db): conn=pymy ...