dp[i][j]表示配对的最大值。

dp[i-1][j]表示s1[i-1]与'-'配对.

dp[i][j-1]表示s2[j-1]与'-'配对.

dp[i-1][j-1]表示s1[i-1]与s2[j-1]配对。

dp[i][j]=max(dp[i-1][j]+mp[s1[i-1]]['-'],dp[i][j-1]+mp['-'][s2[j-1]],dp[i-1][j-1]+mp[s1[i-1]][s2[j-1]]);

#include<stdio.h>
#include<string.h>
#define maxn 110
int dp[maxn][maxn];
int mp[][]={
,-,-,-,-,
-,,-,-,-,
-,-,,-,-,
-,-,-,,-,
-,-,-,-,-
}; char s1[maxn],s2[maxn],c1,c2;
int cal(char c)
{
if(c=='A')return ;
if(c=='C')return ;
if(c=='G')return ;
if(c=='T')return ;
return ;
}
int max(int x,int y)
{
return x>y?x:y;
}
int main()
{
int i,j,t,l1,l2;
scanf("%d",&t);
while(t--)
{
scanf("%d%s",&l1,s1);
scanf("%d%s",&l2,s2);
dp[][]=;
for(i=;i<=l1;i++)
dp[i][]=dp[i-][]+mp[cal(s1[i-])][];
for(i=;i<=l2;i++)
dp[][i]=dp[][i-]+mp[][cal(s2[i-])];
for(i=;i<=l1;i++)
for(j=;j<=l2;j++)
{
dp[i][j]=dp[i-][j-]+mp[cal(s1[i-])][cal(s2[j-])];
dp[i][j]=max(dp[i][j],dp[i-][j]+mp[cal(s1[i-])][]);
dp[i][j]=max(dp[i][j],dp[i][j-]+mp[][cal(s2[j-])]);
}
printf("%d\n",dp[l1][l2]);
}
}

hdu1080 LCS变形的更多相关文章

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

  2. POJ 1080( LCS变形)

    题目链接: http://poj.org/problem?id=1080 Human Gene Functions Time Limit: 1000MS   Memory Limit: 10000K ...

  3. UVA-1625-Color Length(DP LCS变形)

    Color Length(UVA-1625)(DP LCS变形) 题目大意 输入两个长度分别为n,m(<5000)的颜色序列.要求按顺序合成同一个序列,即每次可以把一个序列开头的颜色放到新序列的 ...

  4. HDU1080 【LCS变形】

    题意: 给你每种字符匹配的权值大小,给你两个串,长度小的串可以在小串里面添加空格和大串匹配,问你一个最大匹配权值. 思路: 有点类似于LCS吧,我们在求两个串的LCS的时候,不行的就扔掉了,在这里就是 ...

  5. Advanced Fruits(HDU 1503 LCS变形)

    Advanced Fruits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  6. poj1080--Human Gene Functions(dp:LCS变形)

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

  7. HDU 5791 Two ——(LCS变形)

    感觉就是最长公共子序列的一个变形(虽然我也没做过LCS啦= =). 转移方程见代码吧.这里有一个要说的地方,如果a[i] == a[j]的时候,为什么不需要像不等于的时候那样减去一个dp[i-1][j ...

  8. uva 10723 Cyborg Genes(LCS变形)

    题目:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=107450#problem/C 题意:输入两个字符串,找一个最短的串,使得输入的两个 ...

  9. Combine String---hdu5727 &&& Zipper(LCS变形)

    题目链接:http://poj.org/problem?id=2192 http://acm.split.hdu.edu.cn/showproblem.php?pid=5707 http://acm. ...

随机推荐

  1. 解决hive无法传参问题思路

    由于hive执行过程中参数必须写死,无法进行传递参数.利用shell脚本和java编程进行解决 #!/bin/sh#date = `date -d -1days '+%Y-%m-%d'`if [ $# ...

  2. eclipse设置提示信息

    1.设置 java 文件的代码提示功能  .abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ () 2.设置 xml 文件的代码提示功能 打 开 ...

  3. consul理解

    假设consul软件安装在电脑ComputerA上,那么需要注册的服务ServiceA1也需要安装在电脑ComputerA上, 一个服务就是一个提供了ip+port(或者域名)的应用程序. 服务: 服 ...

  4. [Array]485. Max Consecutive Ones

    Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1, ...

  5. CentOS7 下的 firewall 用法

    1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status firewalld  停止: systemctl disab ...

  6. 解决底部Button遮挡ListView最后一项内容的bug

    项目中ListView和Button经常是一起使用的,用ListView来展示数据,用Button来提交修改的数据或对修改的数据进行确定操作. 假如使用线性布局的话ListView会盖住整个Butto ...

  7. step()动画

    <style type="text/css"> .hi { width: 50px; height: 72px; background-image: url(" ...

  8. PYTHON网络爬虫与信息提取[BeautifulSoup](单元四)

    1 简介 from bs4 import BeautifulSoup soup=BeautifulSoup(<p>data</p>,'html.parser') 2 基本元素 ...

  9. C# dataGridView_CellValueChanged事件

    C# 输入完以后立即更新缓冲区(DataGridView CheckBox列checked变化后就触发CellValueChanged事件) 在DataGridView添加如下的事件( Current ...

  10. WCF 无管理员权限下启用服务

    1 使用 netsh.exe 工具 C:\Windows\system32>netsh http add urlacl url=http://+:8733/WcfServiceLibrary1 ...