hdu 1080 Human Genne Function
来源:互联网 发布:班主任网络研修计划 编辑:程序博客网 时间:2024/05/29 15:04
这道题我不会。dp感觉老是自己写不出来啊,状态转移方程不好建啊,问题抽象。
我一定可以超越其他人,其他人混得比我好,只是因为他们比我早几年工作吧。沉下心来学习,不要被世俗所打扰,守护你的高傲。
用的是dp的思想。
和求最长LCS的思路大体相似。
对于一个序列s1,s2.
用数组dp[i][j]
表示 s1 的第i个字符和s2的第j个字符 比较时最大值 ,,这时分3种情况:
s1[i]==s2[j] : 那么dp[i][j]=dp[i-1][j-1]+val(s1[i],s2[j])s1[i]!=s2[j] ,那么,i 可以和‘-’ 配对,也可以选择和 j-1配对。
dp[i][j]=max(dp[i-1][j]+val(i,’-‘,dp[i][j-1]+val(‘-‘,j)
状态转移方程分析
dp [i][j]= max(dp[i-1][j]+val[i]['-'],dp[i][j-1]+val['-'][j],dp[i-1][j-1]+val[i][j]). (val[i][j]为题中权值)
参考博客: http://blog.csdn.net/w00w12l/article/details/7956797
下面是代码:
#include <iostream>#include<cstring>#include<cstdio>using namespace std;#define mm 105char s1[mm];char s2[mm];int dp[mm][mm];int score[5][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,-10000};int getIndex(char c){ if(c=='A')return 0; else if(c=='C') return 1; else if(c=='G') return 2; else if(c=='T') return 3; else if(c=='-') return 4;}int val(char c,char d){ int i1=getIndex(c); int i2=getIndex(d); return score[i1][i2];}int MAX(int a,int b){ return b>a?b:a;}int main(){ int t; cin>>t; int len1,len2; while(t--){ memset(dp,0,sizeof(dp)); scanf("%d%s",&len1,s1+1); //if index start from 0,then will need index -1 // so index start from 1 scanf("%d%s",&len2,s2+1); for(int i=1;i<=len1;i++){ dp[i][0]=dp[i-1][0]+val(s1[i],'-'); // s1[i] math - } for(int j=1;j<=len2;j++){ dp[0][j]=dp[0][j-1]+val('-',s2[j]); } for(int i=1;i<=len1;i++){ for(int j=1;j<=len2;j++){ dp[i][j]=MAX(dp[i-1][j]+val(s1[i],'-'),dp[i][j-1]+val('-',s2[j])); dp[i][j]=MAX(dp[i-1][j-1]+val(s1[i],s2[j]),dp[i][j]); } } cout<<dp[len1][len2]<<endl; } return 0;}
阅读全文
0 0
- hdu 1080 Human Genne Function
- POJ 1080 HUMAN GENE FUNCTION
- POJ 1080--Human Gene Function
- PKU ACM 1080-human gene function
- hdu 1080 Human Gene Functions
- HDU 1080 Human Gene Functions
- HDU 1080 Human Gene Functions
- 【Hdu】1080 Human Gene Functions
- HDU 1080 Human Gene Functions
- hdu 1080 Human Gene Functions
- hdu 1080 Human Gene Functions
- hdu-1080 Human Gene Functions
- hdu 1080 Human Gene Functions
- hdu 1080 Human Gene Functions
- hdu 1080 Human Gene Functions
- 【算法刷题】poj 1080 Human Gene Function
- poj 1080&&hdu 1080 human gene fucnction
- hdu 1080 ;poj 1080 Human Gene Functions
- 有关Function Try Block的法则
- 构造函数与析构函数的应用
- MySQL 中文乱码问题
- linq to sql
- UVALive
- hdu 1080 Human Genne Function
- 由一道题引发的关于输入输出的总结
- springMVC初识 源码末尾
- 线性表 —— 1
- HDU1282回文数猜想
- opencv3学习之addWeight()函数
- ISP-坏点校正(DPC)
- 卡西欧手表城市编码,调时区用
- hdoj2000_ASCII码排序