基因配对 给出俩基因链和配对的值  求配对值得最大值  简单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的更多相关文章

  1. poj 1080 dp如同LCS问题

    题目链接:http://poj.org/problem?id=1080 #include<cstdio> #include<cstring> #include<algor ...

  2. poj 1080 zoj 1027(最长公共子序列变种)

    http://poj.org/problem?id=1080 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=27 /* zoj ...

  3. 【POJ 1080】 Human Gene Functions

    [POJ 1080] Human Gene Functions 相似于最长公共子序列的做法 dp[i][j]表示 str1[i]相应str2[j]时的最大得分 转移方程为 dp[i][j]=max(d ...

  4. dp poj 1080 Human Gene Functions

    题目链接: http://poj.org/problem?id=1080 题目大意: 给两个由A.C.T.G四个字符组成的字符串,可以在两串中加入-,使得两串长度相等. 每两个字符匹配时都有个值,求怎 ...

  5. poj 1080 Human Gene Functions(dp)

    题目:http://poj.org/problem?id=1080 题意:比较两个基因序列,测定它们的相似度,将两个基因排成直线,如果需要的话插入空格,使基因的长度相等,然后根据那个表格计算出相似度. ...

  6. POJ - 1080 枚举 / DP

    要求max{F/P},先枚举下界lowf,再贪心求符合约束条件的n个最小价值和 记录F的离散值和去重可以大幅度常数优化 (本来想着用DP做的) (辣鸡POJ连auto都Complie Error) # ...

  7. POJ 1080 Human Gene Functions 【dp】

    题目大意:每次给出两个碱基序列(包含ATGC的两个字符串),其中每一个碱基与另一串中碱基如果配对或者与空串对应会有一个分数(可能为负),找出一种方式使得两个序列配对的分数最大 思路:字符串动态规划的经 ...

  8. POJ 1080:Human Gene Functions LCS经典DP

    Human Gene Functions Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18007   Accepted:  ...

  9. POJ 1080 Human Gene Functions -- 动态规划(最长公共子序列)

    题目地址:http://poj.org/problem?id=1080 Description It is well known that a human gene can be considered ...

随机推荐

  1. wamp目录索引图片不显示

    在wampserver安装目录下  \bin\apache\Apache2.2.21\conf\extra\httpd-autoindex.conf Alias /icons/ "c:/Ap ...

  2. 如何修改WAMP中mysql默认空密码&重新登录phpmyadmin

    WAMP安装好后,mysql密码是为空的,那么要如何修改呢?其实很简单,通过几条指令就行了,下面我就一步步来操作. 首先,通过WAMP打开mysql控制台. 提示输入密码,因为现在是空,所以直接按回车 ...

  3. 安全cookie登录状态设计方案

    我们知道web是基于HTTP协议传输的,明文传输是极其危险的,随便哪个抓包工具分析下数据包,就over啦,一个加密的传输过程应该包括两部分,一部分为身份认证,用户鉴别这个用户的真伪:另外一部分为数据加 ...

  4. sersync做实时同步(第一步)

    两台主机,一台主服务器(192.168.0.109).一台目标服务器(192.168.0.212) 1.配置目标服务器(192.168.0.212);就是配置rsync服务器.在配置文件/etc/rs ...

  5. python实现发工资脚本

    好开心啊,在旁边大神的帮助下,终于实现了发工资的python脚本,之前用shell写的老出错,刚才测试,发80个人工资详情,妥妥的,代码如下: from email.mime.multipart im ...

  6. IOS学习之十七:Grand Central Dispatch(GCD)编程基础

    IOS学习之十七:Grand Central Dispatch(GCD)编程基础   有过编程经验的人,基本都会接触到多线程这块. 在java中以及Android开发中,大量的后台运行,异步消息队列, ...

  7. grunt serve Warning: Running "sass:server" (sass) task

    使用grunt serve运行时遇到一问题: y@y:ydkt$ grunt serve Running "serve" task Running "clean:serv ...

  8. VLC命令行的应用

    vlc -vvv rtsp://218.204.223.237:554/live/1/0547424F573B085C/gsfp90ef4k0a6iap.sdp --sout #transcode{v ...

  9. HDU_1010——小狗走迷宫DFS

    Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...

  10. The Black Tux | IT桔子

    The Black Tux | IT桔子 The Black Tux theblacktux.com