我用的dp是n^3的, dp[i][j] 表示在s串的i个前和t串的j个前,s[i],t[j]为最末端的两个串得到的最大值。

状态转移方程为:

之前将s和t串最尾端添加'-'

  1. for(int i=;i<=n;i++)
  2. {
  3. for(int j=;j<=m;j++)
  4. {
  5. if(i==n&&j==m) break;
  6. int tmp=;
  7. for(int k=j-;k>=;k--)
  8. {
  9. dp[i][j]=max(dp[i][j],dp[i-][k]+tmp);
  10. tmp += fuc('-',t[k]);
  11. }
  12. tmp=;
  13. for(int k=i-;k>=;k--)
  14. {
  15. dp[i][j]=max(dp[i][j],dp[k][j-]+tmp);
  16. tmp += fuc('-',s[k]);
  17. }
  18. dp[i][j]+=fuc(s[i],t[j]);
  19. }
  20. }

好的一种做法是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

Problem Description
It is well known that a human gene can be considered as a sequence, consisting of four nucleotides, which are simply denoted by four letters, A, C, G, and T. Biologists have been interested in identifying human genes and determining their functions, because these can be used to diagnose human diseases and to design new drugs for them.

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.

 
Input
The input consists of T test cases. The number of test cases ) (T is given in the first line of the input. Each test case consists of two lines: each line contains an integer, the length of a gene, followed by a gene sequence. The length of each gene sequence is at least one and does not exceed 100. 
 
Output
The output should print the similarity of each test case, one per line. 
 
Sample Input
2
7 AGTGATG
5 GTTAG
7 AGCTATT
9 AGCTTTAAA
 
Sample Output
14
21
 
Source
 
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <algorithm>
  5. #include <math.h>
  6. #include <map>
  7. #include <queue>
  8. #include <sstream>
  9. #include <iostream>
  10. using namespace std;
  11. #define INF 0x3fffffff
  12. #define N 110
  13.  
  14. int n,m;
  15. int dp[N][N];
  16. char s[N];
  17. char t[N];
  18.  
  19. int fuc(char x,char y)
  20. {
  21. if(x==y) return ;
  22. if( (x=='-'&&y=='A') || (y=='-'&&x=='A') ) return -;
  23. if( (x=='-'&&y=='C') || (y=='-'&&x=='C') ) return -;
  24. if( (x=='-'&&y=='G') || (y=='-'&&x=='G') ) return -;
  25. if( (x=='-'&&y=='T') || (y=='-'&&x=='T') ) return -;
  26. if( (x=='A'&&y=='C') || (y=='A'&&x=='C') ) return -;
  27. if( (x=='A'&&y=='G') || (y=='A'&&x=='G') ) return -;
  28. if( (x=='A'&&y=='T') || (y=='A'&&x=='T') ) return -;
  29. if( (x=='C'&&y=='G') || (y=='C'&&x=='G') ) return -;
  30. if( (x=='C'&&y=='T') || (y=='C'&&x=='T') ) return -;
  31. if( (x=='G'&&y=='T') || (y=='G'&&x=='T') ) return -;
  32. }
  33. int main()
  34. {
  35. //freopen("//home//chen//Desktop//ACM//in.text","r",stdin);
  36. //freopen("//home//chen//Desktop//ACM//out.text","w",stdout);
  37. int T;
  38. scanf("%d",&T);
  39. while(T--)
  40. {
  41. scanf("%d%s",&n,s+);
  42. s[++n]='-';
  43. scanf("%d%s",&m,t+);
  44. t[++m]='-';
  45. for(int i=;i<=n;i++)
  46. for(int j=;j<=m;j++)
  47. {
  48. dp[i][j] = -INF;
  49. }
  50. dp[][]=;
  51. // dp[i][j] 表示在s串的i个前,t串的j个前,并且s[i]和t[j]在最尾端,
  52. for(int i=;i<=n;i++)
  53. {
  54. for(int j=;j<=m;j++)
  55. {
  56. if(i==n&&j==m) break;
  57. int tmp=;
  58. for(int k=j-;k>=;k--)
  59. {
  60. dp[i][j]=max(dp[i][j],dp[i-][k]+tmp);
  61. tmp += fuc('-',t[k]);
  62. }
  63. tmp=;
  64. for(int k=i-;k>=;k--)
  65. {
  66. dp[i][j]=max(dp[i][j],dp[k][j-]+tmp);
  67. tmp += fuc('-',s[k]);
  68. }
  69. dp[i][j]+=fuc(s[i],t[j]);
  70. }
  71. }
  72. printf("%d\n",max(dp[n][m-],max(dp[n-][m-],dp[n-][m])));
  73. }
  74. return ;
  75. }

HDU1080(DP)的更多相关文章

  1. hdu1080 DP(类最长公共子序列)

    题意,有两个字符串,分别由四个字母构成,字母之间有不同的相似度,允许在两个字符串都按原顺序排列的情况下进行字母与字母之间的匹配,也可以让字母与空格匹配,即相当于在字符串中间加空格来一一匹配,每个字母与 ...

  2. BZOJ 1911: [Apio2010]特别行动队 [斜率优化DP]

    1911: [Apio2010]特别行动队 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 4142  Solved: 1964[Submit][Statu ...

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

  4. AEAI DP V3.7.0 发布,开源综合应用开发平台

    1  升级说明 AEAI DP 3.7版本是AEAI DP一个里程碑版本,基于JDK1.7开发,在本版本中新增支持Rest服务开发机制(默认支持WebService服务开发机制),且支持WS服务.RS ...

  5. AEAI DP V3.6.0 升级说明,开源综合应用开发平台

    AEAI DP综合应用开发平台是一款扩展开发工具,专门用于开发MIS类的Java Web应用,本次发版的AEAI DP_v3.6.0版本为AEAI DP _v3.5.0版本的升级版本,该产品现已开源并 ...

  6. BZOJ 1597: [Usaco2008 Mar]土地购买 [斜率优化DP]

    1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4026  Solved: 1473[Submit] ...

  7. [斜率优化DP]【学习笔记】【更新中】

    参考资料: 1.元旦集训的课件已经很好了 http://files.cnblogs.com/files/candy99/dp.pdf 2.http://www.cnblogs.com/MashiroS ...

  8. BZOJ 1010: [HNOI2008]玩具装箱toy [DP 斜率优化]

    1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 9812  Solved: 3978[Submit][St ...

  9. px、dp和sp,这些单位有什么区别?

    DP 这个是最常用但也最难理解的尺寸单位.它与“像素密度”密切相关,所以 首先我们解释一下什么是像素密度.假设有一部手机,屏幕的物理尺寸为1.5英寸x2英寸,屏幕分辨率为240x320,则我们可以计算 ...

随机推荐

  1. node定时任务——node-schedule模块使用说明

    在实际开发项目中,会遇到很多定时任务的工作.比如:定时导出某些数据.定时发送消息或邮件给用户.定时备份什么类型的文件等等. 一般可以写个定时器,来完成相应的需求,在node.js中自已实现也非常容易, ...

  2. php中的静态变量

    一.静态变量1.静态变量是只存在于作用域的变量,不过,在函数执行完成以后,这种变量的值不会丢失,也就是说,在下一次调用这个函数时,变量仍会记得原来的值.2.将表达式计算出来的结果付给静态变量是不合法的 ...

  3. atitit.新增编辑功能 跟orm的实现 attilax p31

    atitit.新增编辑功能 跟orm的实现 attilax p31 1. 流程的实现 1 2. view的实现(dwr) 1 3. 获取表结构 1 4. grep filt req params 2 ...

  4. Xamarin for VS 4.0.1.145 Stable版免费完整破解补丁

    Xamarin for VS 4.0.1.145 Stable版免费完整破解补丁 支持Priority最高权限(超企业版)开发, 支持Android, IOS调试.  支持Android打包为Bund ...

  5. Centos7 安装Git-cola

    首先安装Git sudo yum -y install git* 找到 git-all.noarch , 安装这个. sudo yum install git-all.noarch ========= ...

  6. C# fixed详解

    相信很多人在这样或那样的项目中,或者无意间看到了fixed语句块,看到之后你肯定会疑问: 1.这个fixed关键字是做什么用的? 2.什么情况下需要该关键字? 3.这个关键字该怎么用? 我相信解决了上 ...

  7. Python 实现抽象类的两种方式+邮件提醒+动态导入模块+反射(参考Django中间件源码)

    实现抽象类的两种方式 方式一 from abc import ABCMeta from abc import abstractmethod class BaseMessage(metaclass=AB ...

  8. dp背包之01背包poj2184

    http://poj.org/problem?id=2184 题意:给定两个属性,求这两个属性的和的最大值......... 思路:将第一个属性往后平移1000个单位,然后推导其动态转移方程,若是dp ...

  9. Java反射机制在代理模式中的使用

    代理模式的核心思路就是一个接口有两个子类,一个子类完成核心的业务操作,另一个子类完成与核心业务有关的辅助性操作. 代理模式分为静态代理模式和动态代理模式.  静态代理模式: //接口类 interfa ...

  10. 使用js事件机制进行通用操作&特定业务处理的协调

    背景:提供一个通用的功能工具条,工具条会在特定的事件响应时进行一些通用处理:第三方系统使用iframe嵌入这个工具条中,在工具条的特定的事件响应时进行通用处理的时候,有可能第三方系统会有一些自己的业务 ...