一道动态规划,两个串进行匹配,不同字母匹配的值不一样,也可以和空格匹配(空格不能与空格匹配),求最大的匹配值。

数据很弱,每个串都在100以内。

定义dp[i][j]为第一个串前i个数和第二个串前j个数已匹配的匹配值

有三种情况:1.第i个和第j个匹配

                      2.第i个和‘-’匹配

                      3.第j个和‘-’匹配

注意合理初始化

#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<iostream>
#include<cstring>
using namespace std;
int g[5][5]={{5,-1,-2,-1,-3},{-1,5,-3,-2,-4},{-2,-3,5,-2,-2},{-1,-2,-2,5,-1},{-3,-4,-2,-1,0}};
char str1[105];
char str2[105];
map<char,int> m;
int cas;
int dp[105][105];//前i个数和前j个数已匹配的情况
int main()
{
// freopen("input.txt","r",stdin);
int len1,len2;
scanf("%d",&cas);
m['A']=0;
m['C']=1;
m['G']=2;
m['T']=3;
m['-']=4;
while(cas--)
{
scanf("%d%s",&len1,str1);
scanf("%d%s",&len2,str2);
dp[0][0]=0;
for(int i=1;i<=len1;i++)
dp[i][0]=dp[i-1][0]+g[m[str1[i-1]]][4];
for(int i=1;i<=len2;i++)
dp[0][i]=dp[0][i-1]+g[4][m[str2[i-1]]];
for(int i=1;i<=len1;i++)
for(int j=1;j<=len2;j++)
{
int t1=dp[i-1][j-1]+g[m[str1[i-1]]][m[str2[j-1]]];
int t2=dp[i-1][j]+g[m[str1[i-1]]][4];
int t3=dp[i][j-1]+g[4][m[str2[j-1]]];
dp[i][j]=max(t1,max(t2,t3));
}
printf("%d\n",dp[len1][len2]);
}
}

 

zoj1027 Human Gene Functions的更多相关文章

  1. Human Gene Functions

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

  2. 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 ...

  3. poj 1080 ——Human Gene Functions——————【最长公共子序列变型题】

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

  4. 【POJ 1080】 Human Gene Functions

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

  5. poj 1080 Human Gene Functions(lcs,较难)

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

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

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

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

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

  8. 杭电20题 Human Gene Functions

    Problem Description It is well known that a human gene can be considered as a sequence, consisting o ...

  9. 刷题总结——Human Gene Functions(hdu1080)

    题目: Problem Description It is well known that a human gene can be considered as a sequence, consisti ...

随机推荐

  1. 如何在美国公司写project plan 邮件--以hadoop安装和Mahout数据分析为例子

    Hi, XXX (boss name) Project Title:  Hadoop installation and Data analysis based on Mahout Deliverabl ...

  2. MVC思想架构的简单自定义UITableViewCell

         在iOS的开发过程中,架构思想是很重要的一部分,目前的主流应该分为MVC与MVVM两种,在这里不做过多的区分,有兴趣的同学可以看看唐巧大神的一篇文章<被误解的MVC和被神化的MVVM& ...

  3. 【Lucene4.8教程之六】QueryParser与Query子类:如何生成Query对象

    一.概述 1.对于一个搜索而言,其核心语句为: searcher.search(query, 10); 此时,其最重要的参数为一个Qeury对象.构造一个Query对象有2种方法: (1)使用Quer ...

  4. 认识JSONP

    jsonp 全称是JSON with Padding 我们大家都知道ajax是不能发起跨域请求,现在可以通过jsonp来弥补ajax的这一缺陷 通过script标签的src属性就可以实现跨域请求.如( ...

  5. 菜鸟的jQuery源码学习笔记(一)

    整个jQuery是一个自调用的匿名函数: (function(global, factory) { if (typeof module === "object" && ...

  6. wxwidgets demo

    环境说明: IOS: mac 10.9 wx:  wxWidgets-2.9.5  (http://www.wxwidgets.org/downloads/) gcc: $gcci686-apple- ...

  7. Strange fuction--hdu2899

    Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  8. DataSet 中的数据排序 及 DataRow装成DataTable

    1.DataSet 中的数据排序 DataSet ds = new DataSet(); // 获取当前排口的数据 ds = _xiaobill.GetHistoryData(yinZiBianm, ...

  9. 在WPF中自定义你的绘制(三)

    原文:在WPF中自定义你的绘制(三) 在WPF中自定义你的绘制(三)                                                                  ...

  10. JIRA官方:JIRA亮点介绍

    操作超级简单 简单不意味着要以牺牲功能作为代价.JIRA提供了友好.直观的可配置的Web界面,并支持大量的快捷键操作. 跟踪任何事务 跟踪问题.任务.需求,当然还有软件缺陷.定义你自己的事务类型来使之 ...