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 ...
随机推荐
- 模块SEO优化中{分类名称}分隔符去掉及只调用下级分类方法
if($catid) { if($CAT['parentid']) { $seo_catname = ''; $tmp = strip_tags(cat_pos($CAT, 'DESTOON')); ...
- php设计模式 1单例模式
之前很长时间之前就学习过设计模式,但是因为在实践中很少应用,所以忽略了,但现在却意识到设计模式很重要的,程序设计简介高效冗余性代码少. 今天开始把前几天学习的几个设计模式整理一下,首先当然是单例模式. ...
- 关于Bayes网络新解
经典贝叶斯网络 贝叶斯分类器的分类原理是通过某对象的先验概率,利用贝叶斯公式计算出其后验概率,即该对象属于某一类的概率,选择具有最大后验概率的类作为该对象所属的类.目前研究较多的贝叶斯分类器主要有四种 ...
- JDBC连接mysql,TOMCAT错误: Cannot convert value '0000-00-00 00:00:00' from column 10 to TIMESTAMP
解决思路依据如下URL: http://blog.csdn.net/stail111/article/details/5640109 问题:MySQL数据库,如果数据库中日期字段为空为值为'0000- ...
- SGU 0438 The Glorious Karlutka River =) 动态流
题目大意:有一条东西向流淌的河,宽为W,河中有N块石头,每块石头的坐标(Xi, Yi)和最大承受人数Ci已知.现在有M个游客在河的南岸,他们想穿越这条河流,但是每个人每次最远只能跳D米,每跳一次耗时1 ...
- Android调用系统相机和文件浏览器
//拍照功能,调用系统的相机功能 Intent intent2 = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResul ...
- Android录音服务
MediaRecorder Mediarecorder=new MediaRecorder();//创建一个MediaRecorder对象 Mediarecorder.setAudioSource(M ...
- zookeeper[5] zookeeper集群配置及伪集群配置
参考:http://zookeeper.apache.org/doc/trunk/zookeeperStarted.html 集群配置: 1.配置文件conf/zoo.cfg,除了单机模式的配置之外, ...
- JAXB--学习1
一.简介 JAXB(Java Architecture for XML Binding) 是一个业界的标准,是一项可以根据XML Schema产生Java类的技术.该过程中,JAXB也提供了将XML实 ...
- String path = request.getContextPath();这段什么用
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+ ...