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#:文件操作(待补充)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...
- 输出流格式化(以操纵子方式格式化,以ios类成员函数方式格式化)
一.以操纵子方式格式化 数据输入输出的格式控制使用系统头文件<iomanip>中提供的操纵符.把它们作为插入操作符<<的输出对象即可.如setiosflags.setw.set ...
- memset 与 memcpy
1. memset 需要的头文件 在C中 <string.h> 在C++中 <cstring> 原型: void *memset(void *s, int ch, size_t ...
- 关于“Could not open ServletContext resource [/WEB-INF/applicationContext.xml]”解决方案
问题说明,我在web.xml文件中进行了如下配置 <servlet> <servlet-name>dispatcherServlet</servlet-name> ...
- ctags高级用法
1.ctags -R 有个问题,成员变量没有包含在里面.所以自动完成对象的成员时没有提示.解决办法:$ctags -R --fields=+iaS --extra=+q *–fields=[+|-]f ...
- plink参数说明
Plink: command-line connection utilityRelease 0.67Usage: plink [options] [user@]host [command] ...
- Atitit.404错误解决标准流程and url汉字中文路径404错误resin4 resin chinese char path 404 err解决
Atitit.404错误解决标准流程and 错误resin4 resin chinese char path 404 err解决 1. #原因解析 1 2. #解决方式 2 3. 输出图片流... 2 ...
- Objective-C的内存管理(一)黄金法则的理解
转自:http://blog.csdn.net/lonelyroamer/article/details/7666851 一.内存管理黄金法则: The basic rule to apple is ...
- JavaScript判断浏览器类型及版本(新增IE11)
$(function () { var Sys = {}; var ua = navigator.userAgent.toLowerCase(); var s; (s = ua.match(/rv:( ...
- tornado WebSocket详解
1.什么是WebSocketwebsocket和长轮询的区别是客户端和服务器之间是持久连接的双向通信.协议使用ws://URL格式,但它在是在标准HTTP上实现的. 2.tornado的WebSock ...