ZOJ 1027 Human Gene Functions(dp)

YOLOv8+ByteTrack实战:5分钟搞定多目标跟踪(附鱼群检测调参秘籍) 本文详细介绍了如何利用YOLOv8和ByteTrack快速实现多目标跟踪,特别针对鱼群检测等复杂场景提供参数调优秘籍。通过环境配置、核心机制解析和专项调优技巧,开发者可在5分钟内搭建高效跟踪系统,适用于水产养殖、交通监控等实际应用。文章还包含工程落地方案和性能优化建议,帮助实现精准的鱼群计数与行为分析。 阅读详情

Human Gene Functions

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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 �C 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 �CGT--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


Output for the Sample Input

14
21


Source: Asia 2001, Taejon (South Korea)
Submit    Status




#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>

#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define bug printf("hihi\n")

#define eps 1e-12

typedef long long ll;

using namespace std;
#define INF 0x3f3f3f3f
#define N 205

int dp[N][N];
int va[1000][1000];

char a[N],b[N];
int lena,lenb;

void inint()
{
    va['A']['A']=5;
    va['A']['C']=-1;
    va['A']['G']=-2;
    va['A']['T']=-1;
    va['A']['-']=-3;

    va['C']['A']=-1;
    va['C']['C']=5;
    va['C']['G']=-3;
    va['C']['T']=-2;
    va['C']['-']=-4;

    va['G']['A']=-2;
    va['G']['C']=-3;
    va['G']['G']=5;
    va['G']['T']=-2;
    va['G']['-']=-2;

    va['T']['A']=-1;
    va['T']['C']=-2;
    va['T']['G']=-2;
    va['T']['T']=5;
    va['T']['-']=-1;

    va['-']['A']=-3;
    va['-']['C']=-4;
    va['-']['G']=-2;
    va['-']['T']=-1;
}

char step[6]={"AGCT-"};

void solve()
{
     int i,j;
     memset(dp,-INF,sizeof(dp));
     dp[0][0]=0;
     for(int i=0;i<=lena;i++)
        for(int j=0;j<=lenb;j++)
     {
         if(i==0&&j==0) continue;
         if(i&&j) dp[i][j]=dp[i-1][j-1]+va[a[i]][b[j]];
         if(i>0) dp[i][j]=max(dp[i][j],dp[i-1][j]+va[a[i]]['-']);
         if(j>0) dp[i][j]=max(dp[i][j],dp[i][j-1]+va['-'][b[j]]);
     }
}

int main()
{
    inint();
   int i,j,t;
   scanf("%d",&t);
   while(t--)
   {
      scanf("%d%s",&lena,a+1);
      scanf("%d%s",&lenb,b+1);
      solve();
      printf("%d\n",dp[lena][lenb]);
   }
 return 0;
}

/*

2
7 AGTGATG
5 GTTAG
7 AGCTATT
9 AGCTTTAAA

*/


微信小程序 - {“errMsg”:”requestPayment:fail banned”} 微信小程序调用wx.requestPayment支付失败返回错误(uniapp微信小程序微信支付报错) {“errMsg”:”requestPayment:fail banned”},微信小程序调用wx.requestPayment报错requestPayment:fail banned,uni-app微信小程序wx.requestPayment支付报错requestPayment:fail banned,拉起小程序支付报错,iPhone苹果ios真机微信支付报错,Android安卓手机微信支付报错,支付报错,商户配置,签名验证,uniapp 小程序支付微信支付一场,设置过b2b类目,确认了商户号相关功能正常 阅读详情

相关推荐

黏菌算法(Slime Mould Algorithm,SMA)

这是一篇关于黏菌算法的总结博客,包含算法思想,算法步骤,求函数最值(Python实现),算法改进等,持续更新ing

weixin_46838605的博客 1万+

ZOJ -027动态规划解答方法

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1027 Human Gene Functions Time Limit: 2 Seconds Memory Limit: 65536 KB It is well known that a human gene can be considered a

rually的专栏 1275

别再到处找密钥了!手把手教你搞定Halcon 24.11/25.05的试用授权(附每月更新提醒)

本文详细介绍了Halcon 24.11/25.05试用授权的获取与配置方法,包括解密新版授权机制、快速配置指南、每月更新规律及多版本共存管理技巧。帮助开发者避免常见授权问题,提升工作效率,特别适合机器视觉领域的初学者和专业人士。

weixin_29238147的博客 1247

求两个DNA序列的最长公共子序列

新冠状病毒的基因序列 2019年12月下旬,武汉出现了多例不明原因的病毒性肺炎病例。之后,中国疾病预防控制中心确定此次致病的病原体为一种新的冠状病毒。1月12日,世界卫生组织将其命名为“2019新型冠状病毒(2019-nCoV)”。为了弄清新型冠状病毒的起源,中国疾控中心等机构的研究人员对住院患者的样本进行高通量测序,获得了完整和部分的2019-nCoV基因组序列。接着对这些2019-nCoV基因...

qq_45013991的博客 2457

STM32 W5500 Freemodbus Modbus TCP协议功能实现

STM32F103VCT6 W5500(SPI1),实现Modbus-TCP协议的功能

坚韧与专注 2万+

红队内网攻防渗透:内网渗透之内网对抗:实战项目&VPC1打靶&PHP-RCE&三层代理路由&防火墙上线&密码喷射&域控提权

上面已经抓取到了密码,但是我们通过拓扑分析看,要想上线win10只能通过正向shell,因为win7的防火墙是开的,win10反向主动连接肯定入站规则拦截,而win10自己没有开防火墙,所以win7主动正向连接就可以上线。win7开启了防火墙,入站规则肯定是会拦截我们的请求的,所以我们需要反向上线,让win7主动来连接我们。这里扫描发现是存在ms17010漏洞的,但是想上线192.168.2.142的话,我们没有路由是上线不了的,这里有两种办法:一种msf直接生成后门,另一种cs移植后门到msf。

HACKONE的博客 914

动态规划PTA总结

数字三角形;最长公共子序列;单调递增最长子序列;最大子段和;最大矩阵和问题

罗马尼亚硬拉 1178

uniapp微信小程序 - 详解map地图markers图标不显示问题,自定义图标真机调试不显示变成默认marker标记点图标(解决微信小程序map组件markers自定义图标失效,兼容安卓苹果手机)

uniapp微信小程序 map地图markers图标不显示,markers图标真机调试不显示,uniapp map地图显示图标markers问题,自定义图标不显示,添加marker后不显示,uniapp 微信小程序 map marker图标不显示如何解决,uniapp小程序地图的marker图标不显示问题,微信小程序map组件markers自定义图标真机显示问题,uni-app, 微信小程序, map组件, markers图标不显示, 真机调试, 微信小程序map组件,地图加载后marker标记点ios设备

🏆 前端领域优质创作者 2924

ZOJ-1027-Human Gene Functions

这道题的AC率很高啊,有50%多,觉得有些奇怪,感觉应该在30%才对,不管了。需要说明的是这一题中使用的分值矩阵map[][]是经过我变形的,这样变形后,使用起来会更加方便,尤其是对于X对-的情况可以直接减去表示的值就是它们之间的分值,当然,相应在输入时也已经把字母变成了数字方便后面直接用做map矩阵的下标查表。这道题是很正统的DP动态规划,所以采用了标志矩阵check表示是否计算

outer of the space 1487

Debezium 性能调优实战:吞吐量、延迟与资源平衡

摘要: 本文分享了团队如何通过系统性调优将Debezium从初始3,200 TPS/2.8秒延迟提升至15,200 TPS/210ms延迟的实战经验。优化涵盖四个层面:1)Debezium连接器配置(批处理、快照并行、消息精简);2)Kafka分区策略与Avro序列化缓存;3)JVM改用ZGC及OS参数调优;4)MySQL的binlog与I/O优化。关键发现包括分区数黄金公式、sync_binlog调整带来56%的I/O负载下降,以及避免盲目增大队列内存等陷阱。最终实现吞吐量提升4.75倍,并强调性能调优需

爱丹丹的博客 361

3.详解Labview串口通讯--从串口线连接到串口通讯保姆级教程

本文非常详细的介绍了使用Labview实现串口通讯,读完题主这篇文章,即使你是今天刚下载的Labview,也能熟练的连接并驱动串口执行,接下来和我一起学习下,记得关注并点赞不迷路

关注我,更多技术问题欢迎私聊~ 1万+

ZOJ-1027* 基因串匹配

1027:给出两串基因判断相似度。不同的匹配关系由下表分值决定 [img]http://dl.iteye.com/upload/attachment/535585/9a593d87-3c7a-31da-bf23-80d0a97b827e.gif[/img] 两串基因串长度不一定相等。用-补齐,其中-和-不能匹配。求最大匹配分值。 如 A G T G A T G - G T ...

linest 364

Unity3D实现项目限制功能(使用次数限制和时间限制)

大家好,我是心疼你的一切,不定时更新Unity开发技巧,觉得有用记得一键三连哦。在软件开发的时候,可能会遇到程序的使用次数限制,以及时间的限制,下面就写一下这两种方法是新建注册表,增加键值对,修改键值,完成对程序的控制提示:以下是本篇文章正文内容,下面案例可供参考以上就是讲了两种限制方法不定时更新Unity开发技巧,觉得有用记得一键三连哦。

心疼你的一切博客 1818

zoj 1027 DP Human Gene Functions

此题满足动态规划求解条件:1. 最优子结构性质 2. 重叠子问题性质 每个位置可能有三种情况:1. 第一个序列被插入‘_' 2. 第二个序列被插入'_' 3. 两个都不插入,直接匹配 最优值的递归定义为c[i][j] = max(c[i-1][j-1] + arr[sx[i]][sy[j]], c[i][j-1] + arr[4][sy[j]], c[i-1][j] + arr[sx[i]

coobj2008的专栏 573

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

ZOJ 1027 Human Gene Functions【DP】

f(i, j - 1) + cost(’ - ', b[j]), // b[j] 与 ‘-’ 配。f(i - 1, j) + cost(a[i], ’ - ') // a[i] 与 ’ - ’ 配。转移方程:f(i , j ) = max { f(i - 1, j - 1) + cost(a[i], b[j]), // a[i] 与 b[j] 匹配。f(i, j)表示用a串的前 i 个字符与b串的前 j 个字符所构造的最优串的代价。给定两个基因串,求最大相似度。

qq_61832249的博客 170

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

ZOJ 1027 Human Gene Functions (DP)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1027题目意思:计算两个核苷酸序列的相似性。可以通过插入-符号,将两个核苷酸对应,每对核苷酸都有相应的分数。目标是求两个核苷酸序列通过对齐操作得到的最大分数。如AGTGATG和GTTAG,通过对齐AGTGATG和-GTTA-G可以得到最大分数为(-3)+5+5

老和山之子 644

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

ZOJ 1027 Human Gene Functions(DP)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1027 设f[i][j]为基因1的前 i 个核苷酸与基因2的前 j 个核苷酸匹配所得的最高分数。 则 f[i][j]= max { f[i-1][j-1]+ score[i][j], //基...

weixin_33921089的博客 141

ZOJ1027-Human Gene Functions(dp)

Human Gene Functions Time Limit: 2 Seconds      Memory Limit: 65536 KB It is well known that a human gene can be considered as a sequence, consisting of four nucleotides, which are simply deno

H煊的博客 528

zoj1027 Human Gene Functions(DP)

/*经典模型:最长公共子序列 */ View Code 1 #include <iostream> 2 #include <cstdlib> 3 4 using namespace std; 5 6 int Geno[ 210 ][ 210 ]; 7 int Matr[ 5 ][ 5 ] = { 8 { 5,-1,-2,-1,-3}, 9 ...

weixin_30952535的博客 110

zoj 1027 Human Gene Functions

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1027本题是一道典型的DP问题,刚开始学习DP问题,不怎么会,看了别人解题报告..T_T定义函数f(i,j),(0那么该如何用DP求f(i,j)呢?分三种情况:1.让Xi与‘-’进行匹配:则f1(i,j) = f(i-1,j) + value(Xi,-

/0 739

Human Gene Functions

ZOJ1027 Human Gene Functions http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=27 思路:算是最长公共子序列的拓展。。 设第一个字符串用char[] x存储 第二个字符串用char[] y存储 如果检索到 x 的第 i 个字符, y 的第 j 个字符,那么就只有三个选择方式。 1)x[i] 与 ‘-’...

Charles_zzz的博客 361

ZOJ1027 POJ1080 Human Gene Functions

非常经典的一条DP题,见以下代码/******************************************************************************* * Author : Neo Fung * Email : neosfung@gm

Neo Fung的专栏 1087

zoj 1027 - Human Gene Functions

题目:计算两个DNA串的,最大权值公共子序列。

小白菜又菜 882

ZOJ 1027 Human Gene Functions

典型的DP,跟《算法导论》的最长公共子串很像。第一次有点粗心,两次次提交后AC。 #include #define SPACE '-' int GetTableIndex(char c) { switch(c) { case 'A': return 0; case 'C':

kelvingu616的专栏 476

zoj1027 Human Gene Functions

一道动态规划,两个串进行匹配,不同字母匹配的值不一样,也可以和空格匹配(空格不能与空格匹配),求最大的匹配值。 数据很弱,每个串都在100以内。 定义dp[i][j]为第一个串前i个数和第二个串前j个数已匹配的匹配值 有三种情况:1.第i个和第j个匹配 2.第i个和‘-’匹配 3.第j个和‘-’匹配 ...

weixin_30511107的博客 149

HDU 1080 || ZOJ 1027 Human Gene Functions

分三种情况考虑: 1、s1不是 -,s2是 -                  dp[i][0] = dp[i - 1][0] + m[x[i]][4];                                   2、s1是 -,s2不是 -                  dp[0][j] = dp[0][j - 1] + m[4][y[j]];

恋&空的专栏 555
上一篇: ZOJ 2059 The Twin Towers(dp)
下一篇: Light oj 1095 - Arrange the Numbers(错排)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值