HDU1080 【LCS变形】
题意:
给你每种字符匹配的权值大小,给你两个串,长度小的串可以在小串里面添加空格和大串匹配,问你一个最大匹配权值。
思路:
有点类似于LCS吧,我们在求两个串的LCS的时候,不行的就扔掉了,在这里就是不行的就给他匹配了一个空格;
dp[i][j-1] j匹配空格;
dp[i-1][j] i匹配空格;
dp[i-1][j-1] i和j匹配;
初始化
dp[i][0] i匹配空格
dp[0][j] j匹配空格
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>PII;
const double eps=1e-5;
const double pi=acos(-1.0);
const int INF=0x3f3f3f3f;
int temp[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
}; int change(char x)
{
if(x=='A')
return 0;
if(x=='C')
return 1;
if(x=='G')
return 2;
if(x=='T')
return 3;
return 4;
} int s1[110];
int s2[110];
int dp[110][110];
char s[110]; int main()
{
int len1,len2;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%s",&len1,s+1);
// memset(dp,0,sizeof(dp));
dp[0][0]=0; memset(s1,0,sizeof(s1));
memset(s2,0,sizeof(s2));
for(int i=1;i<=len1;i++)
{
s1[i]=change(s[i]);
dp[i][0]=dp[i-1][0]+temp[s1[i]][4];
}
scanf("%d%s",&len2,s+1);
for(int i=1;i<=len2;i++)
{
s2[i]=change(s[i]);
dp[0][i]=dp[0][i-1]+temp[4][s2[i]];
} for(int i=1;i<=len1;i++)
{
for(int j=1;j<=len2;j++)
{
dp[i][j]=-INF;
dp[i][j]=max(dp[i][j],max(dp[i-1][j-1]+temp[s1[i]][s2[j]],max(dp[i-1][j]+temp[s1[i]][4],dp[i][j-1]+temp[4][s2[j]])));
}
} printf("%d\n",dp[len1][len2]);
}
return 0;
}
HDU1080 【LCS变形】的更多相关文章
- hdu1080 LCS变形
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 ...
- 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 ...
- POJ 1080( LCS变形)
题目链接: http://poj.org/problem?id=1080 Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K ...
- UVA-1625-Color Length(DP LCS变形)
Color Length(UVA-1625)(DP LCS变形) 题目大意 输入两个长度分别为n,m(<5000)的颜色序列.要求按顺序合成同一个序列,即每次可以把一个序列开头的颜色放到新序列的 ...
- Advanced Fruits(HDU 1503 LCS变形)
Advanced Fruits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- poj1080--Human Gene Functions(dp:LCS变形)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17206 Accepted: ...
- HDU 5791 Two ——(LCS变形)
感觉就是最长公共子序列的一个变形(虽然我也没做过LCS啦= =). 转移方程见代码吧.这里有一个要说的地方,如果a[i] == a[j]的时候,为什么不需要像不等于的时候那样减去一个dp[i-1][j ...
- uva 10723 Cyborg Genes(LCS变形)
题目:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=107450#problem/C 题意:输入两个字符串,找一个最短的串,使得输入的两个 ...
- Combine String---hdu5727 &&& Zipper(LCS变形)
题目链接:http://poj.org/problem?id=2192 http://acm.split.hdu.edu.cn/showproblem.php?pid=5707 http://acm. ...
随机推荐
- Spring Cloud Config的配置中心获取不到最新配置信息的问题
Spring Cloud Config的配置中心获取不到最新配置信息的问题 http://blog.didispace.com/spring-cloud-tips-config-tmp-clear/
- vi 之行号操作---显示行号、跳到指定行
1.设置行号显示 esc ->:->set nu 2.跳到指定行 esc-> 123gg 3. 进入命令模式 ?一:在冒号下输入 vim vi 在命令模式中 使用 d(版本不同 使用 ...
- yii框架之gii创建数据表相应的model类
一.首先是在数据库中建立project须要的表: 二.然后,配置相应文件: 在project文件夹下yiiProject\protected\config\main.php.在50行定义了db应用组件 ...
- Nginx下的https配置
https: https(Secure Hypertext Transfer Protocol) 安全超文本传输协议 它是以安全为目标的http通道,即它是http的安全版.它使用安全套接字层(SSL ...
- 百度之星2016资格赛D,水题
很简单的题,主要是要用字符串哈希,把字符串处理成整数.接下来可以继续用hash,也可以像我一样用个map就搞定了. /* * Author : ben */ #include <cstdio&g ...
- 九度OJ 1105:字符串的反码 (翻译)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4929 解决:1529 题目描述: 一个二进制数,将其每一位取反,称之为这个数的反码.下面我们定义一个字符的反码.如果这是一个小写字符,则它 ...
- LNK1112: module machine type 'x64' conflicts with target machine type 'X86'
1 什么是“module machine type” 这个是当前工程要链接的静态库的target machine type. 2 什么是“target machine type” 这个是当前工程生成的 ...
- 删除SVN账号
删除里面的所有文件 C:\Users\Administrator\AppData\Roaming\Subversion\auth
- matlab面向对象设计---类的概念和使用
代码: classdef MadgwickAHRS < handle %MADGWICKAHRS Implementation of Madgwick's IMU and AHRS algori ...
- appium(3)-Running Tests
Running Tests Preparing your app for test (iOS) Test apps run on the simulator have to be compiled ...