(DP)HDU 1080 Human Gene Functions
2013-08-01 09:24
423 查看
/*状态转移方程:dp[i][j]=max(dp[i-1][j]+w[s1[i]]['-'],dp[i][j-1]+w['-'][s2[j]],dp[i-1][j-1]+w[s1[i]][s2[j]]) dp[i-1][j]+w[s1[i]]['-']表示s1中的字符与'-'相匹配得到的值; dp[i][j-1]+w['-'][s2[j]]表示'-'与s2中的字符相匹配得到的值; dp[i-1][j-1]+w[s1[i]][s2[j]]表示s1中的字符与s2中的字符相匹配得到的值; */ #include <iostream> #include <cstdio> #define INF 10000000 #define max(a,b) a>b?a:b using namespace std; int w[6][6]={ 0,0,0,0,0,0, 0,5,-1,-2,-1,-3, 0,-1,5,-3,-2,-4, 0,-2,-3,5,-2,-2, 0,-1,-2,-2,5,-1, 0,-3,-4,-2,-1,-INF, }; /*将字符型转化为整型*/ int getint(char c) { if(c=='A') return 1; else if(c=='C') return 2; else if(c=='G') return 3; else if(c=='T') return 4; else return 5; } /*得到一个权值*/ int weight(char c1,char c2) { int a=getint(c1); int b=getint(c2); return w[a][b]; } int dp[365][365]; int main() { // freopen("in.txt","r",stdin); int i,j; int t; int n1,n2; char s1[105]; char s2[105]; scanf("%d",&t); while(t--) { scanf("%d %s",&n1,s1+1); scanf("%d %s",&n2,s2+1); /*第0列赋值,就是s1与'-'的权值*/ for(i=1;i<=n1;i++) { dp[i][0]=dp[i-1][0]+weight(s1[i],'-'); } /*第0行赋值,就是'-'与s2的权值*/ for(i=1;i<=n2;i++) { dp[0][i]=dp[0][i-1]+weight('-',s2[i]); } for(i=1;i<=n1;i++) //表示s1 { for(j=1;j<=n2;j++) //表示s2 { dp[i][j]=max(dp[i-1][j]+weight(s1[i],'-'),dp[i][j-1]+weight('-',s2[j])); dp[i][j]=max(dp[i][j],dp[i-1][j-1]+weight(s1[i],s2[j])); } } for(i=0;i<=n1;i++) { for(j=0;j<=n2;j++) { cout<<dp[i][j]<<' '; } cout<<endl; } printf("%d\n",dp[n1][n2]); } return 0; }
相关文章推荐
- HDU - 1080 Human Gene Functions DP
- HDU 1080 Human Gene Functions DP -
- 【DP|LCS】HDU-1080 Human Gene Functions
- Hdu 1080 Human Gene Functions(DP)
- hdu 1080 Human Gene Functions 很霸气的DP
- hdu 1080 Human Gene Functions (dp)
- hdu 1080 Human Gene Functions 线性dp
- HDU 1080 Human Gene Functions (DP,最长公共子序列)
- hdu 1080 Human Gene Functions dp
- hdu 1080 Human Gene Functions(DP)
- POJ 1080 && HDU 1080 Human Gene Functions(dp)
- hdu 1080 Human Gene Functions(dp)
- hdu 1080 Human Gene Functions(dp)
- HDU 1080 Human Gene Functions (DP)
- hdu 1080 dp Human Gene Functions
- pku1080 Human Gene Functions DP
- POJ 1080 Human Gene Functions(dp)
- hdu 1080 Human Gene Functions
- hdu 1080 Human Gene Functions
- HDU 1080 Human Gene Functions 动态规划 + DFS