题目大意:

两个字符串,可以再中间任何插入空格,然后让这两个串匹配,字符与字符之间的匹配有各自的分数,求最大分数

最长公共子序列模型。

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的更多相关文章

  1. 杭电20题 Human Gene Functions

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

  2. 【POJ 1080】 Human Gene Functions

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

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

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

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

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

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

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

  6. Human Gene Functions

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

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

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

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

  9. Human Gene Functions POJ 1080 最长公共子序列变形

    Description It is well known that a human gene can be considered as a sequence, consisting of four n ...

随机推荐

  1. Python第五章-内置数据结构02-列表

    Python 内置的数据结构 二.列表(list) 想一想: 前面学习的字符串可以用来存储一串信息,那么想一想,怎样存储咱们班所有同学的名字呢? 定义100个变量,每个变量存放一个学生的姓名可行吗?有 ...

  2. ML Lecture 0-1: Introduction of Machine Learning

    本博客是针对李宏毅教授在Youtube上上传的课程视频<ML Lecture 0-1: Introduction of Machine Learning>的学习笔记.在Github上也po ...

  3. SFDC 401 最新考试真题

    上周通过了SFDC 401 考试,一下是对考试题的回忆. 1. Using a formula field how would a developer calculate the number of ...

  4. python之进程,线程

    什么是进程(process)? 程序并不能单独运行,只有将程序装载到内存中,系统为它分配资源才能运行,而这种执行的程序就称之为进程.程序和进程的区别就在于:程序是指令的集合,它是进程运行的静态描述文本 ...

  5. ubuntu 如何在命令行打开当前目录

    nautilus /var 打开var文件夹

  6. Prism 源码解读6-事件聚合

    0 介绍 事件提供的是1对多的绑定,通过委托链实现对订阅者的调用,事件必须要通过发布者调用.同时事件订阅是强引用,事件订阅者的生命周期总是大于等于事件发布者.如果代码中事件很多就会充斥着各种事件的订阅 ...

  7. Ubuntu复制粘贴快捷键

    复制:[Ctrl+Insert] 粘贴:[Shitf+Insert]

  8. Hystrix 使用手册 | 官方文档翻译

    由于时间关系可能还没有翻译全,但重要部分已基本包含 本人水平有限,如有翻译不当,请多多批评指出,我一定会修正,谢谢大家.有关 ObservableHystrixCommand 我有的部分选择性忽略了, ...

  9. A 拜访奶牛

    时间限制 : - MS   空间限制 : 65536 KB  评测说明 : 时限1000ms 问题描述 经过了几周的辛苦工作,贝茜终于迎来了一个假期.作为奶牛群中最会社交的牛,她希望去拜访N(1< ...

  10. mysql慢查询分析工具比较与实战

    00 前言 在进行mysql性能优化的时候,第一个想到的便是查看慢sql. 但是对于慢sql有没有什么好的工具进行分析呢? 推荐两个工具mysqldumpslow及pt-query-digest. m ...