hdu 1080 Human Gene Functions(dp)

北大POJ1080-Human Gene Functions 立即下载

Human Gene Functions

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1506    Accepted Submission(s): 840


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

 

思路:dp[i][j]为两个序列前i位与前j位最优配对的值。

          s【】【】为对准分数g1【】为第一个序列g2[]为第二个序列

         也就是三种配对中取最大,g1[i]与空,空与g2[j],g[i]与g[j]

          dp[i][j]=max(dp[i-1][j]+s[g1[i-1]]['-'],dp[i][j-1]+s['-'][g2[j-1]],dp[i-1][j-1]+s[g1[i-1]][g2[j-1]]);

 

dai代码:

#include<iostream>
#include<cstring>
using namespace std;
const int mm=110;
int s[][5]={{5,-1,-2,-1,-3},
            {-1,5,-3,-2,-4},
            {-2,-3,5,-2,-2},
            {-1,-2,-2,5,-1},
            {-3,-4,-2,-1,0}
};
int dp[mm][mm];
char g1[mm],g2[mm];
int len1,len2;
int k(char x)
{
  if(x=='A')return 0;
  if(x=='C')return 1;
  if(x=='G')return 2;
  if(x=='T')return 3;
  return 4;
}
int main()
{
  int cas;
  while(cin>>cas)
  {while(cas--)
    {cin>>len1>>g1>>len2>>g2;
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=len1;i++)///边界条件全空与序列配对
      dp[i][0]=dp[i-1][0]+s[k(g1[i-1])][k('-')];
    for(int i=1;i<=len2;i++)
      dp[0][i]=dp[0][i-1]+s[k('-')][k(g2[i-1])];
    for(int i=1;i<=len1;i++)
      for(int j=1;j<=len2;j++)
    {
        dp[i][j]=max(dp[i][j-1]+s[k('-')][k(g2[j-1])],max(dp[i-1][j]+s[k(g1[i-1])][k('-')],
                                                          dp[i-1][j-1]+s[k(g1[i-1])][k(g2[j-1])]));
    }
    cout<<dp[len1][len2]<<"\n";
   }
  }
}


 

 

 

2026.1.9:最新VSCode集成claude插件完美解决方案,跳过登录界面,使用国内Kimi K2进行计费 本文介绍了如何安装配置Claude插件并连接Kimi K2 API的详细步骤:1)搜索安装Claude插件;2)进入设置关闭登录提示;3)在settings.json中添加API配置,包括ANTHROPIC_AUTH_TOKEN(需替换为Kimi API Key)和ANTHROPIC_BASE_URL;4)通过Kimi官网获取API Key。完成配置后即可正常使用该插件。文中配有完整的操作截图指引。 阅读详情

相关推荐

ECU-TEST新手入门:从软件申请到第一个测试包创建的完整保姆级流程

本文详细介绍了ECU-TEST软件从申请试用、安装配置到创建第一个测试包的完整流程。针对新手用户,提供分步指导,包括界面认知、测试组件添加、变量定义及执行结果分析,帮助快速掌握汽车电子测试工具的基本操作。特别说明试用授权的两种获取方式和安装注意事项。

weixin_30606461的博客 481

hdu1080 Human Gene Functions(LCS变形)

Human Gene Functions Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1338Accepted Submission(s): 767 Problem Description It is well ...

angtongyou1893的博客 295

金蝶云星空API实战:从零到一,用Postman打通业务数据流

本文详细介绍了如何使用Postman调试金蝶云星空API,从创建第三方应用到实战调试技巧,帮助开发者快速打通业务数据流。文章重点讲解了API配置的关键细节、常见问题排查方法以及自动化测试方案,提升开发效率与准确性。

weixin_33712987的博客 518

Human Gene Functions(dp)

题目描述 众所周知,人类基因可以认为是一个基因序列,包含四种核苷酸,分别用A,C,T和G四个字母简单地表示。生物学家对鉴别人类基因并确定他们的功能很感兴趣,因为这对诊断人类疾病和开发新药很有用。…… 你的任务是编写一个程序,按以下规则比较两个基因并确定它们的相似程度。 给出两个基因AGTGATG和GTTAG,他们有多相似呢?测量两个基因相似度的一种方法称为对齐。使用对齐方法,可以在基因的适当位置插进空格,让两个基因的长度相等,然后根据基因分值矩阵计算分数。 例如,给AGTGATG插入一个空格,就得到AGT

qq_51772871的博客 822

拆解一个800G光模块:手把手带你认识里面的MT插芯和光纤阵列(FA)

本文详细拆解了800G光模块中的关键组件MT插芯和光纤阵列(FA),揭示了并行光学技术如何实现高速数据传输。通过显微镜下的精密观察,展示了MT插芯的高精度构造和光纤阵列的连接奥秘,同时解析了高精度研磨工艺对光信号传输的重要性。这些微型组件是高速收发模块实现800Gbps带宽的核心技术。

weixin_30839881的博客 1547

MTK Linux Charger驱动分析(二) - power_supply_core.c

的核心作用可以概括为:提供统一的电源管理框架;管理电源设备注册、属性访问、事件通知;封装sysfs 接口和 uevent 通知,屏蔽硬件细节;驱动开发者只需要实现,不关心底层通知和接口细节。简单来说,它是电源子系统的“大脑和中枢”,具体的电池/充电器只是“信息源”。

iTom1900 1488

PKU1080 Human Gene Functions

/*Human Gene FunctionsTime Limit: 1000MS        Memory Limit: 10000KTotal Submissions: 6974        Accepted: 3861DescriptionIt is well known that a human gene can be considered as a sequen

zonelight的专栏 792

从零开始:使用COLMAP与OpenMVS构建高精度三维Mesh模型

本文为零基础新手提供了使用COLMAP与OpenMVS构建高精度三维Mesh模型的完整实战指南。详细介绍了从环境配置、数据采集黄金法则,到COLMAP稀疏与稠密重建、OpenMVS网格生成与纹理映射的每一步操作,并分享了关键的避坑技巧与参数调优建议,帮助读者从二维照片中成功重建出属于自己的三维模型。

metal的博客 505

Human Gene Functions(动态规划)

描述: 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 id

Gabriel_tzc的博客 779

华为交换机实战:如何用ACL+流分类精准限制特定IP的网速(附完整命令)

本文详细介绍了华为交换机如何通过ACL+流分类技术实现精准IP限速,包括ACL规则配置、流分类关联、流行为定义及流策略应用等完整步骤。文章提供了实战命令和配置验证方法,帮助网络管理员有效管理带宽资源,解决特定IP占用过多带宽的问题。

weixin_29229055的博客 100

微信文件自动归档!手把手教你用OpenClaw搭个自己的“数字员工”,告别重复劳动

很多人说“AI是未来”,但未来不是靠喊口号的。OpenClaw的真正价值,是让你把重复劳动交出去,把时间留给真正需要创造力的事。这事真能干,而且不难。下载OpenClaw(GitHub仓库按我写的步骤跑一遍遇到坑,评论区留言——我亲自帮你看作者后记:上周五,我让AI自动归档了文件后,终于在5点准时下班。回家路上,我给它发了条消息:“干得漂亮”。它没回,但我知道——它在默默等我的下一条指令。

2601_94871597的博客 413

最长公共子序列及其变形(Human Gene Functions)(新加了一些内容)

今天我想讲一下最长公共子序列的问题,希望会对读者有很大的帮助。(我希望读者可以坚持看完) 首先我们来一个最简单(相对于最长公共子序列的题来说)的题目: 最长公共子序列问题 Time Limit: 1000MS Memory limit: 65536K 题目描述  给定两个序列X= 输入 输入数据有多组,每组有两行 ,每行为一个长

大众博客 1045

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

HDU 1080 Human Gene Functions (DP)

http://acm.hdu.edu.cn/showproblem.php?pid=1080 求添加  ‘-’ 后的 最大的组合值 状态转移方程: dp[i][j]=max(dp[i-1][j-1]+num[s1[i]][s2[j]], dp[i-1][j]+num[s1[i]][5], dp[i][j-1]+num[5][s2[j]] ); 由于 dp[i][0] 和dp[0][i] 的状

Napoleon 896

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

HDU 1080 Human Gene Functions DP -

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1080 #include #include #include #include using namespace std; const int maxn=100+5; const int INF=0x3f3f3f3f; #define max3(a,b,c) max(a,max(b,c)) ch

BRCOCOLI的博客 304

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

hdu 1080 Human Gene Functions dp

代码: #include #include #include #include #include #include #include #include #include #include using namespace std; const int maxn=110; int dp[maxn][maxn]; int e[5][5]={ {5,-1,-

冷月之殇 804

hdu 1080 Human Gene Functions 简单dp

传送门 http://acm.hdu.edu.cn/showproblem.php?pid=1080题意: - 给出两串 dna 序列, 每个碱基之间匹配得分不同要求匹配出最大得分分析: - dp[i][j] 代表匹配到第一串第 i 个和第二串第 j 个时的最大得分

nktif 309

hdu 1080 dp Human Gene Functions

分三种情况考虑。 dp[i][j]=max(dp[i-1][j-1]+a[s1[i]][s2[j]],max(dp[i-1][j]+a[s1[i]][4],dp[i][j-1]+a[s2[j]][4])); #include using namespace std; int max(int a,int b) { return a>b?a:b; } int main() { in

夜月 492

HDU 1080 Human Gene Functions dp

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1080   最大公共字符串的变形啊   xh[i][j]表示s1串前i个元素于s2串的前j个元素比较的最大值 分3中情况 1:s1[i]于s2[j]直接比较 xh[i][j]=xh[i-1][j-1]+cmp(s1[i],s2[j]); 2:s1[i]于‘-’比较 xh[i][j

lamborghini1993 966

HDU - 1080 Human Gene Functions(基础dp)

Human Gene Functions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3819    Accepted Submission(s): 2178 Problem Description It is wel

HHH_go_的博客 546

hdu 1080 Human Gene Functions--DP

#include char s1[110],s2[110]; int d[110][110]; int p[5][5]={{0,-3,-4,-2,-1},{-3,5,-1,-2,-1},{-4,-1,5,-3,-2},{-2,-2,-3,5,-2},{-1,-1,-2,-2

634

hdu1080 Human Gene Functions DP

Human Gene FunctionsTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3905    Accepted Submission(s): 2226Problem DescriptionIt is well known that...

残梦听雨 333

hdu 1080 Human Gene Functions 很霸气的DP

Human Gene Functions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1307    Accepted Submission(s): 752 Problem Description It is we

hnust_xiehonghao的专栏 1342

hdu 1080 Human Gene Functions 线性dp

#include<bits/stdc++.h> using namespace std; int a[128][128]; void init() { memset(a,0,sizeof(a)); a['A']['A']=5; a['A']['C']=-1; a['A']['G']=-2; a['A']['T']=-1; a['A']['-']=-3;

禅境花园 446

HDU 1080 Human Gene Functions 基础dp

dp黑洞再次凭一己之力写对了一道dp水题,这个题很简单,跟最长公共子序列一样。 #include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;string.h&gt; #include&lt;algorithm&gt; #include&lt;cmath&gt; using namespace std; int t,f[105][10...

weixin_39399748的博客 230

HDU - 1080 Human Gene Functions DP

http://acm.hdu.edu.cn/showproblem.php?pid=1080 题意:           给定两个字符串 s1 和 s2 ,在两个串中都可以插入空格,使两个串的长度最后相等,然后开始匹配,怎样插入空格由匹配规则得到的值最大。 状态转移方程:           dp[i][j] = Max( dp[i-1][j] + val(str1[i],'-

菜鸟成长ing 473
上一篇: hdu 1078 FatMouse and Cheese(记忆化搜索)
下一篇: CF-12D - Ball(排序+MAP)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值