HDU1080(DP)
我用的dp是n^3的, dp[i][j] 表示在s串的i个前和t串的j个前,s[i],t[j]为最末端的两个串得到的最大值。
状态转移方程为:
之前将s和t串最尾端添加'-'
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(i==n&&j==m) break;
int tmp=;
for(int k=j-;k>=;k--)
{
dp[i][j]=max(dp[i][j],dp[i-][k]+tmp);
tmp += fuc('-',t[k]);
}
tmp=;
for(int k=i-;k>=;k--)
{
dp[i][j]=max(dp[i][j],dp[k][j-]+tmp);
tmp += fuc('-',s[k]);
}
dp[i][j]+=fuc(s[i],t[j]);
}
}
好的一种做法是n^2的dp,dp[i][j]表示s串的i个前,和t串的j个前,得到的最大值,其中s[i],t[j]并不一定要是最末端的元素.
状态转移方程是:
dp[i][j]=max(dp[i-1][j-1]+cos(s[i],t[j]),max(dp[i-1][j]+cos('-',s[i]),dp[i][j-1]+cos('-',t[j])));
Human Gene Functions
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1752 Accepted Submission(s): 988
A human gene can be identified through a series of time-consuming biological experiments, often with the help of computer programs. Once a sequence of a gene is obtained, the next job is to determine its function. One of the methods for biologists to use in determining the function of a new gene sequence that they have just identified is to search a database with the new gene as a query. The database to be searched stores many gene sequences and their functions – many researchers have been submitting their genes and functions to the database and the database is freely accessible through the Internet.
A database search will return a list of gene sequences from the database that are similar to the query gene. Biologists assume that sequence similarity often implies functional similarity. So, the function of the new gene might be one of the functions that the genes from the list have. To exactly determine which one is the right one another series of biological experiments will be needed.
Your job is to make a program that compares two genes and determines their similarity as explained below. Your program may be used as a part of the database search if you can provide an efficient one.
Given two genes AGTGATG and GTTAG, how similar are they? One of the methods to measure the similarity of two genes is called alignment. In an alignment, spaces are inserted, if necessary, in appropriate positions of the genes to make them equally long and score the resulting genes according to a scoring matrix.
For example, one space is inserted into AGTGATG to result in AGTGAT-G, and three spaces are inserted into GTTAG to result in –GT--TAG. A space is denoted by a minus sign (-). The two genes are now of equal length. These two strings are aligned:
AGTGAT-G
-GT--TAG
In this alignment, there are four matches, namely, G in the second position, T in the third, T in the sixth, and G in the eighth. Each pair of aligned characters is assigned a score according to the following scoring matrix.
* denotes that a space-space match is not allowed. The score of the alignment above is (-3)+5+5+(-2)+(-3)+5+(-3)+5=9.
Of course, many other alignments are possible. One is shown below (a different number of spaces are inserted into different positions):
AGTGATG
-GTTA-G
This alignment gives a score of (-3)+5+5+(-2)+5+(-1) +5=14. So, this one is better than the previous one. As a matter of fact, this one is optimal since no other alignment can have a higher score. So, it is said that the similarity of the two genes is 14.
7 AGTGATG
5 GTTAG
7 AGCTATT
9 AGCTTTAAA
21
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <sstream>
#include <iostream>
using namespace std;
#define INF 0x3fffffff
#define N 110 int n,m;
int dp[N][N];
char s[N];
char t[N]; int fuc(char x,char y)
{
if(x==y) return ;
if( (x=='-'&&y=='A') || (y=='-'&&x=='A') ) return -;
if( (x=='-'&&y=='C') || (y=='-'&&x=='C') ) return -;
if( (x=='-'&&y=='G') || (y=='-'&&x=='G') ) return -;
if( (x=='-'&&y=='T') || (y=='-'&&x=='T') ) return -;
if( (x=='A'&&y=='C') || (y=='A'&&x=='C') ) return -;
if( (x=='A'&&y=='G') || (y=='A'&&x=='G') ) return -;
if( (x=='A'&&y=='T') || (y=='A'&&x=='T') ) return -;
if( (x=='C'&&y=='G') || (y=='C'&&x=='G') ) return -;
if( (x=='C'&&y=='T') || (y=='C'&&x=='T') ) return -;
if( (x=='G'&&y=='T') || (y=='G'&&x=='T') ) return -;
}
int main()
{
//freopen("//home//chen//Desktop//ACM//in.text","r",stdin);
//freopen("//home//chen//Desktop//ACM//out.text","w",stdout);
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%s",&n,s+);
s[++n]='-';
scanf("%d%s",&m,t+);
t[++m]='-';
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
{
dp[i][j] = -INF;
}
dp[][]=;
// dp[i][j] 表示在s串的i个前,t串的j个前,并且s[i]和t[j]在最尾端,
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(i==n&&j==m) break;
int tmp=;
for(int k=j-;k>=;k--)
{
dp[i][j]=max(dp[i][j],dp[i-][k]+tmp);
tmp += fuc('-',t[k]);
}
tmp=;
for(int k=i-;k>=;k--)
{
dp[i][j]=max(dp[i][j],dp[k][j-]+tmp);
tmp += fuc('-',s[k]);
}
dp[i][j]+=fuc(s[i],t[j]);
}
}
printf("%d\n",max(dp[n][m-],max(dp[n-][m-],dp[n-][m])));
}
return ;
}
HDU1080(DP)的更多相关文章
- hdu1080 DP(类最长公共子序列)
题意,有两个字符串,分别由四个字母构成,字母之间有不同的相似度,允许在两个字符串都按原顺序排列的情况下进行字母与字母之间的匹配,也可以让字母与空格匹配,即相当于在字符串中间加空格来一一匹配,每个字母与 ...
- BZOJ 1911: [Apio2010]特别行动队 [斜率优化DP]
1911: [Apio2010]特别行动队 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 4142 Solved: 1964[Submit][Statu ...
- 2013 Asia Changsha Regional Contest---Josephina and RPG(DP)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4800 Problem Description A role-playing game (RPG and ...
- AEAI DP V3.7.0 发布,开源综合应用开发平台
1 升级说明 AEAI DP 3.7版本是AEAI DP一个里程碑版本,基于JDK1.7开发,在本版本中新增支持Rest服务开发机制(默认支持WebService服务开发机制),且支持WS服务.RS ...
- AEAI DP V3.6.0 升级说明,开源综合应用开发平台
AEAI DP综合应用开发平台是一款扩展开发工具,专门用于开发MIS类的Java Web应用,本次发版的AEAI DP_v3.6.0版本为AEAI DP _v3.5.0版本的升级版本,该产品现已开源并 ...
- BZOJ 1597: [Usaco2008 Mar]土地购买 [斜率优化DP]
1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4026 Solved: 1473[Submit] ...
- [斜率优化DP]【学习笔记】【更新中】
参考资料: 1.元旦集训的课件已经很好了 http://files.cnblogs.com/files/candy99/dp.pdf 2.http://www.cnblogs.com/MashiroS ...
- BZOJ 1010: [HNOI2008]玩具装箱toy [DP 斜率优化]
1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 9812 Solved: 3978[Submit][St ...
- px、dp和sp,这些单位有什么区别?
DP 这个是最常用但也最难理解的尺寸单位.它与“像素密度”密切相关,所以 首先我们解释一下什么是像素密度.假设有一部手机,屏幕的物理尺寸为1.5英寸x2英寸,屏幕分辨率为240x320,则我们可以计算 ...
随机推荐
- 学习C#——性能计数器
写在前面: 作为Web应用开发前线的一枚小兵,每看到“性能”一词总有种要亮瞎眼的感觉,说到“性能”那就不能不提“数据”,在程序猿.攻城师中不是流行这样一句话吗?“无图无真相”,谁要说谁开发的应用性能有 ...
- lintcode---线段树查询||(区间元素个数)
对于一个数组,我们可以对其建立一棵 线段树, 每个结点存储一个额外的值 count 来代表这个结点所指代的数组区间内的元素个数. (数组中并不一定每个位置上都有元素) 实现一个 query 的方法,该 ...
- DevExpress中GridControl列转义的实现方法
/// <summary> /// CustomColumnDisplayText Helper /// </summary> /// <param name=" ...
- Centos7 安装Git-cola
首先安装Git sudo yum -y install git* 找到 git-all.noarch , 安装这个. sudo yum install git-all.noarch ========= ...
- 【C语言】23-typedef
一.typedef作用简介 * 我们可以使用typedef关键字为各种数据类型定义一个新名字(别名). 1 #include <stdio.h> 2 3 typedef int Integ ...
- Qt打开文件对话框
项目中需要打开文件对话框,就查了一下,不得不说Qt的帮助文档做的真好,非常详细.要实现这个功能有两种方式,使用QFileDialog的静态方法,实例化QFileDialog对象. 基本算是照抄帮助文档 ...
- Windows操作系统下 使用c++ WIN32API禁用控制台最小化和关闭按钮
#include<Windows.h> //屏蔽控制台最小按钮和关闭按钮 HWND hwnd = GetConsoleWindow(); HMENU hmenu = GetSystemMe ...
- 基于jdom 的 xmluti
package cn.com.do1.wechat.common; import org.jdom.Attribute; import org.jdom.Document; import org.jd ...
- 本系列love2d示例代码错误集中整理
3.输入和音乐 音乐不是循环播放的,可以在love.audio.play(music) 之前添加music:setLooping(true)
- am335x 打开内部 RTC
AM335X 打开内部 RTC 过程记录. kernel version: 3.2.0 先在 make menuconfig 里面打开内部RTC的配置: make menuconfig Device ...