poj 1080 dp
基因配对 给出俩基因链和配对的值 求配对值得最大值 简单dp
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
const int maxa = ;
const int mina = -;
char str1[maxa], str2[maxa];
int num[][] = {
, -, -, -, -,
-, , -, -, -,
-, -, , -, -,
-, -, -, , -,
-, -, -, -,-
};
int a1[maxa], a2[maxa];
int dp[maxa][maxa];
int main(){
//freopen("in.cpp", "r", stdin);
int t, n1, n2;
scanf("%d", &t);
while(t--){
str1[] = ;
str2[] = ;
scanf("%d%s", &n1, str1+);
scanf("%d%s", &n2, str2+);//printf("*"); for(int i = ; i <= n1; i++){
// printf("%c", str1[i]);
if(str1[i] == 'A')
str1[i] = ;
else if(str1[i] == 'C')
str1[i] = ;
else if(str1[i] == 'G')
str1[i] = ;
else str1[i] = ;
}
for(int i = ; i <= n2; i++){//printf("%d\n", i);
if(str2[i] == 'A')
str2[i] = ;
else if(str2[i] == 'C')
str2[i] = ;
else if(str2[i] == 'G')
str2[i] = ;
else str2[i] = ;
}//printf("*");
for(int i = ; i <= n1; i++){
if(i == )
a1[i] = num[str1[i]][];
else a1[i] = num[str1[i]][] + a1[i-];
}
for(int i = ; i <= n2; i++){
if(i == )
a2[i] = num[str2[i]][];
else a2[i] = num[str2[i]][] + a2[i-];
}
/*for(int i =0; i <= n1; i++){
printf("%d ", a1[i]);
}puts("");*/
for(int i = ;i <= n1; i++){
for(int k = ; k <= n2; k++){
dp[i][k] = mina;
}
}
for(int i = ; i <= n2; i++){
if(i == )
dp[][i] = num[str1[]][str2[i]];
else
dp[][i] = num[str1[]][str2[i]] + a2[i-]-a2[];
}
for(int i = ; i <= n1; i++){
dp[i][] = a1[i] - a1[];
for(int k = ; k <= n2; k++){
dp[i][k] = max(dp[i][k], dp[i-][k]+ num[str1[i]][]);
for(int j = ; j < k; j++){
dp[i][k] = max(dp[i][k],dp[i-][j] + num[str1[i]][str2[k]] + a2[k-] - a2[j]);
}
}
}
/*for(int i = 1; i <= n1; i++){
printf("*%d ", num[str1[i]][str2[1]]+a1[i-1]-a1[0]);
}puts("");;
for(int i = 0; i <= n1; i++){
for(int k = 0; k <= n2; k++){
printf("%d%d %d ",str1[i], str2[k], dp[i][k]);
}puts("");
}*/
int ans = mina;
for(int i = ; i <= n2; i++){
ans = max(ans, dp[n1][i] + a2[n2] - a2[i]);
// printf("%d ", dp[n1][i] + a2[n2] - a2[i]);
}//puts("");
for(int i = ; i <= n1; i++){
ans = max(ans, dp[i][n2]+a1[n1] - a1[i]);
//printf("%d ", dp[i][n2]+a1[n1] - a1[i]);
}//puts("");
printf("%d\n", ans);
} }
poj 1080 dp的更多相关文章
- poj 1080 dp如同LCS问题
题目链接:http://poj.org/problem?id=1080 #include<cstdio> #include<cstring> #include<algor ...
- 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 ...
- dp poj 1080 Human Gene Functions
题目链接: http://poj.org/problem?id=1080 题目大意: 给两个由A.C.T.G四个字符组成的字符串,可以在两串中加入-,使得两串长度相等. 每两个字符匹配时都有个值,求怎 ...
- poj 1080 Human Gene Functions(dp)
题目:http://poj.org/problem?id=1080 题意:比较两个基因序列,测定它们的相似度,将两个基因排成直线,如果需要的话插入空格,使基因的长度相等,然后根据那个表格计算出相似度. ...
- POJ - 1080 枚举 / DP
要求max{F/P},先枚举下界lowf,再贪心求符合约束条件的n个最小价值和 记录F的离散值和去重可以大幅度常数优化 (本来想着用DP做的) (辣鸡POJ连auto都Complie Error) # ...
- POJ 1080 Human Gene Functions 【dp】
题目大意:每次给出两个碱基序列(包含ATGC的两个字符串),其中每一个碱基与另一串中碱基如果配对或者与空串对应会有一个分数(可能为负),找出一种方式使得两个序列配对的分数最大 思路:字符串动态规划的经 ...
- POJ 1080:Human Gene Functions LCS经典DP
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18007 Accepted: ...
- POJ 1080 Human Gene Functions -- 动态规划(最长公共子序列)
题目地址:http://poj.org/problem?id=1080 Description It is well known that a human gene can be considered ...
随机推荐
- nginx配置使其支持thinkphp的pathinfo模式
#user root;#user nobody;worker_processes 1; #error_log logs/error.log;#error_log logs/error.log noti ...
- acdream暴力专场中的优美暴力
F - 小晴天老师系列——苹果大丰收 Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Other ...
- UVA 1600 Patrol Robot
带状态的bfs 用一个数(ks)来表示状态-当前连续穿越的障碍数: step表示当前走过的步数: visit数组也加一个状态: #include <iostream> #include & ...
- SQL通过xml插入批量数据
存储过程: CREATE PROCEDURE [dbo].[UP_PurchasexxxCard] @OrderInfo XMLASBEGIN SET NOCOUNT ON; DECLARE @Dat ...
- Altium中Fill,Polygon Pour,Plane的区别和用法
Fill:表示绘制一块实心的铜皮,将区域中的所有连线和过孔连接在一块,而不考虑是否属于同一个网络.假如所绘制的区域中有VCC和GND两个网络,用Fill命令会把这两个网络的元素连接在一起,这样就有可能 ...
- C51程序优化
1.指针: 对于大部分的编译器,使用指针比使用数组生成的代码更短,执行效率更高.但是在Keil中则相反,使用数组比使用的指针生成的代码更短.通常使用自加.自减指令和复合赋值表达式(如a-=1及a+=1 ...
- 2个Web上传组件
http://www.uploadify.com/download/ http://gmupload.tanjun.com.cn/
- 2014-07-28 使用Axure RP进行手机端BBS的原型设计
今天是在吾索实习的第14天.因本公司的微信公众号需要有一个对外的技术交流平台,所以我们小组打算设计一个手机端的BBS以满足其要求.首先,我们需要做的是进行数据库设计与原型设计,然后提交给经理验收,看看 ...
- DLL模块:C++在VS下创建、调用dll
1.dll的优点 代码复用是提高软件开发效率的重要途径.一般而言,只要某部分代码具有通用性,就可将它构造成相对独立的功能模块并在之后的项目中重复使用.比较常见的例子是各种应用程序框架,ATL.MFC等 ...
- HDU_2024——判断字符串是否是c语言合法标识符
Problem Description 输入一个字符串,判断其是否是C的合法标识符. Input 输入数据包含多个测试实例,数据的第一行是一个整数n,表示测试实例的个数,然后是n行输入数据,每行是 ...