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与C++中非常少犯的错误,犯了后却非常难找出的错误
1.continue,break类的错误(HDU1877): #include<iostream> using namespace std; int main() { int a,b,m, ...
- Object-C中的字符串对象1-不可变字符串
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...
- Atitit.注解and属性解析(2)---------语法分析 生成AST attilax总结 java .net
Atitit.注解and属性解析(2)---------语法分析 生成AST attilax总结 java .net 1. 应用场景:::因为要使用ui化的注解 1 2. 使用解释器方式来实现生成 ...
- Unity3D学习(十一):关于UI销毁后图集仍然无法释放问题的解决办法
前言 最近进行项目性能优化的时候发现的问题. 问题 从大厅进到单局的过程中,会经过选择英雄和加载两个流程,这两个流程对应的UI界面都会有一张几mb左右的贴图作为背景,在进入单局游戏后这两个UI已经销毁 ...
- JS学习笔记(5)--一道返回整数数组的面试题(经验之谈)
说明: 1. 微信文章里看到的,作者是马超 网易高级前端技术经理,原文在网上搜不到,微信里可以搜“为什么你的前端工作经验不值钱?”,里面写着“转载自网易实践者社区”.(妈蛋,第二天网上就有了http: ...
- 基于jQuery左侧小图滚动右侧大图显示代码
今天给大家分享一款 jQuery左侧小图滚动右侧大图显示代码是一款基于jQuery实现的左侧滚动图片点击大图查看效果代码.该实例适用浏览器:IE8.360.FireFox.Chrome.Safari. ...
- PHP——动态随机数
取1-13随机数 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...
- Java范型之T extends Comparable<? super T>
在观察Java源码的时候,发现了这么一个写法T extends Comparable<? super T>.不禁纳闷为什么要这么写呢?有什么好处吗,extends和super在这里的作用着 ...
- HeadFirst Jsp 09 (JSTL)
JSTL (jsp standard tag library) 标准标记库 JSTL 安装, 注意你的每一个项目都需要一个 JSTL副本, 并把它放在WEB-INF/lib 目录下, 在 Tomcat ...
- shell向python传参数
想要在shell中调用python脚本时实现: python pyServer.py argu1 argu2 argu3 利用 sys.argv 即可读取到 相应参数: # coding=utf-8 ...