hdu poj 1080 Human Gene Functions LCS 动态规划
来源:互联网 发布:网络新媒体的传播特征 编辑:程序博客网 时间:2024/05/30 23:20
题意:给定两DNA序列,在序列中任意位置可以插入-和另外一个碱基匹配,每种匹配有个分值,求匹配的最大分值
思路:用dp[I][j]代表放a中第I个,与放b中第j个字符时的最大分值。
什么都不放dp[0][0]=0
在a前面加上与b长度相同的‘-’,与b全部匹配
dp[0][I]=dp[0][I-1]+map[4][a[I-1] (1=<I<=b.size)
在b前面加上与a长度相同的'-',与a全部匹配
dp[I][0]=dp[I-1][0]+map[4][b[I-1] (1=<I<=a.size)
#include<cstdio>#include<cstring>#include<string>#include<iostream>using namespace std;const int maxn =110;int a[maxn],b[maxn];int l1,l2;int map[5][5]={{5,-1,-2,-1,-3},//A 0 ,C 1,G 2 T 3 , - 4{-1,5,-3,-2,-4},{-2,-3,5,-2,-2},{-1,-2,-2,5,-1},{-3,-4,-2,-1,0}};int dp[maxn][maxn];int Max(int a,int b,int c){int d=a>b?a:b;int e=c>d?c:d;return e;}int main(){int t;char c;while(scanf("%d",&t)!=EOF){while(t--){memset(dp,0,sizeof(dp));scanf("%d",&l1);getchar();for(int i=0;i<l1;i++){scanf("%c",&c);if(c=='A')a[i]=0;if(c=='C')a[i]=1;if(c=='G')a[i]=2;if(c=='T')a[i]=3;if(c=='-')a[i]=4;}scanf("%d",&l2);getchar();for(int i=0;i<l2;i++){scanf("%c",&c);if(c=='A')b[i]=0;if(c=='C')b[i]=1;if(c=='G')b[i]=2;if(c=='T')b[i]=3;if(c=='-')b[i]=4;}dp[0][0]=0;for(int i=1;i<=l1;i++)dp[i][0]=dp[i-1][0]+map[4][a[i-1]];for(int i=1;i<=l2;i++)dp[0][i]=dp[0][i-1]+map[4][b[i-1]];int x1,x2,x3;x1=x2=x3=0;for(int i=1;i<=l1;i++)for(int j=1;j<=l2;j++){x1=dp[i-1][j]+map[4][a[i-1]];x2=dp[i][j-1]+map[4][b[j-1]];x3=dp[i-1][j-1]+map[a[i-1]][b[j-1]];dp[i][j]=Max(x1,x2,x3);}printf("%d\n",dp[l1][l2]);}}}
0 0
- hdu poj 1080 Human Gene Functions LCS 动态规划
- POJ-1080-Human Gene Functions-LCS变体,动态规划,DP
- Human Gene Functions - LCS 动态规划 HDU-1080
- poj 1080 Human Gene Functions动态规划
- POJ 1080 Human Gene Functions(动态规划)
- [POJ 1080]Human Gene Functions(动态规划)
- hdu 1080 Human Gene Functions 动态规划
- POJ 1080 Human Gene Functions(动态规划——LCS问题变形)
- POJ 1080 Human Gene Functions DP(LCS)
- POJ 1080 Human Gene Functions(LCS)
- POJ 1080 Human Gene Functions(LCS变形)
- POJ 1080 Human Gene Functions(DP LCS)
- poj 1080 Human Gene Functions lcs
- POJ 1080 Human Gene Functions(DP:LCS)
- POJ 1080 Human Gene Functions(LCS变形)
- hdu 1080 Human Gene Functions(LCS&DP)
- 【DP|LCS】HDU-1080 Human Gene Functions
- hdu 1080 Human Gene Functions (LCS变形)
- 平均年龄
- linux之类似Windows的资源管理器gnome-system-monitor(可用这个杀死进程)
- 软连接与硬链接的区别
- [整理]php常用函数及运用场景----数组函数
- 进程的一些基本概念
- hdu poj 1080 Human Gene Functions LCS 动态规划
- C—动态内存分配之malloc与realloc的区别
- Java多线程创建
- 浅谈jQuery源码(三)——$.inArray
- Android——操作数据库-增删改查-案例《商品展示》
- windows下训练FCN模型所遇到的问题
- 朴素贝叶斯分类器
- 【IMWeb训练营作业01 vue todos】
- 一个关于shiro的问题,有大兄弟知道的话进来指点下