杭电1080 J - Human Gene Functions
题目大意:
两个字符串,可以再中间任何插入空格,然后让这两个串匹配,字符与字符之间的匹配有各自的分数,求最大分数
最长公共子序列模型。
dp[i][j]表示当考虑吧串1的第i个字符和串2的第j个字符时,当前的最大分数,当前有3中可能,
1,i与j直接匹配,那么这个状态是由dp[i-1][j-1]转移过来的.
2,i与空格匹配,那么j就要与i-1匹配了,由dp[i-1][j]转移过来。
3,j与空格匹配,那么i就要与j-1匹配了,由dp[i][j-1]转移过来。
dp的初始值,dp[i][0]与dp[0][i]分别表示串1和串2的第i个字符与空格匹配
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e9+;
const ll N=+;
ll dp[N][N];char s1[N],s2[N];
ll mp[N][N];
void inll()
{
mp['A']['A']= ;
mp['A']['C']=-;
mp['A']['G']=-;
mp['A']['T']=-;
mp['A'][] =-; mp['C']['A']=-;
mp['C']['C']= ;
mp['C']['G']=-;
mp['C']['T']=-;
mp['C'][] =-; mp['G']['A']=-;
mp['G']['C']=-;
mp['G']['G']= ;
mp['G']['T']=-;
mp['G'][] =-; mp['T']['A']=-;
mp['T']['C']=-;
mp['T']['G']=-;
mp['T']['T']= ;
mp['T'][] =-; mp[]['A']=-;
mp[]['C']=-;
mp[]['G']=-;
mp[]['T']=-;
}
void solve()
{
memset(dp,,sizeof dp);
ll n;
ll m;
cin>>n;
cin>>s1+;
cin>>m;
cin>>s2+;
for(ll i=;i<=n;i++) dp[i][]=dp[i-][]+mp[s1[i]][]; for(ll i=;i<=m;i++) dp[][i]=dp[][i-]+mp[][s2[i]]; for(ll i=;i<=n;i++)
{
for(ll j=;j<=m;j++)
{
dp[i][j]=max(dp[i-][j]+mp[s1[i]][],dp[i][j-]+mp[][s2[j]]);
dp[i][j]=max(dp[i-][j-]+mp[s1[i]][s2[j]],dp[i][j]);
}
}
cout<<dp[n][m]<<endl;
}
int main()
{
ios::sync_with_stdio();
inll();
ll t;
cin>>t;
while(t--) solve();
return ;
}
杭电1080 J - Human Gene Functions的更多相关文章
- 杭电20题 Human Gene Functions
Problem Description It is well known that a human gene can be considered as a sequence, consisting o ...
- 【POJ 1080】 Human Gene Functions
[POJ 1080] Human Gene Functions 相似于最长公共子序列的做法 dp[i][j]表示 str1[i]相应str2[j]时的最大得分 转移方程为 dp[i][j]=max(d ...
- 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——————【最长公共子序列变型题】
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17805 Accepted: ...
- poj 1080 Human Gene Functions(lcs,较难)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19573 Accepted: ...
- Human Gene Functions
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18053 Accepted: 1004 ...
- 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 ...
- POJ 1080 Human Gene Functions -- 动态规划(最长公共子序列)
题目地址:http://poj.org/problem?id=1080 Description It is well known that a human gene can be considered ...
- Human Gene Functions POJ 1080 最长公共子序列变形
Description It is well known that a human gene can be considered as a sequence, consisting of four n ...
随机推荐
- url,解释器,响应器,版本控制,分页
路由控制 -基本路由写法:咱们一直写的
- [Docker8]Dockerfiles
Comment INSTRUCTION arguments FROM 基于哪个base镜像 RUN 执行命令并创建新的镜像层,run经常用于安装软件包 MAINTAINER 镜像创建者 copy 将文 ...
- 【java I/O流总结】基于源码比较FileReader和BufferReader
上一篇博客中,测试分析了FileReader&FileWriter,和BufferWriter&BufferReader之间的性能对比.仅仅只是简单分析.现在我基于源码的角度,来分析B ...
- [BFS,大水题] Codeforces 198B Jumping on Walls
题目:http://codeforces.com/problemset/problem/198/B Jumping on Walls time limit per test 2 seconds mem ...
- CMD 基础命令
基本命令 1.编译.java文件成.class:找到文件所在路径 --> java -d . 文件名称.java --> javac -d . 文件名称.java : 2.ping URL ...
- Building Applications with Force.com and VisualForce(Dev401)(十八):Visualforce Pages: Introduction to Visualforce
Dev401-020:Visualforce Pages: Introduction to Visualforce Course Objectives1.Understand the benefits ...
- python数据分析工具 | matplotlib
不论是数据挖掘还是数学建模,都免不了数据可视化的问题.对于 Python 来说,matplotlib 是最著名的绘图库,它主要用于二维绘图,当然也可以进行简单的三维绘图.它不但提供了一整套和 Matl ...
- [教程]KALI LINUX 2.0 2019 更新国内源
2019年最新版本KALI 为 KALI 2019.1 下载地址:https://www.kali.org/downloads/ 有的新入门的朋友可能会问,为什么每次都无法手动更新 例如:Update ...
- pyspider_初始
一.简介 1.1.简介 pyspider 是一个使用python编写,并且拥有强大功能web界面的爬虫框架. 强大的web界面可进行脚本编辑,任务监控,项目管理,结果查看等功能. pyspider支持 ...
- python:*args和**kwargs的用法
1.*args用来将参数打包成tuple给函数体调用 代码: # *args用来将参数打包成tuple给函数体调用 def func(*args): print(args,type(args)) fu ...