HEU 8004 Human Gene Functions

/**************************************
Problem: HEU 8004 Human Gene Functions
Time: 0.0090 s
Memory: 580 k 
Accepted Time: 2009-05-21 14:57:55
Tips: DP 
http://hi.baidu.com/fandywang_jlu/blog/item/205d37f3c7e2d5c90a46e01a.html
*************************************
*/

#include 
<stdio.h>
int table[5][5]={     5,-1,-2,-1,-3,
                    
-15,-3,-2,-4,
                    
-2,-35,-2,-2,
                    
-1,-2,-25,-1,
                    
-3,-4,-2,-10}
;
int main()
{
    
int n,i,j;
    
int a[109][109];
    
char b[10]={"ACGT"};
    scanf(
"%d",&n);
    
while(n--)
    
{
        
char str1[109],str2[109];
        
int len1,len2;
        scanf(
"%d%s%d%s",&len1,str1+1,&len2,str2+1);
        
for(i=1;i<=len1;i++)
        
{
            
for(j=0;j<4;j++)
            
{
                
if(str1[i]==b[j])
                
{
                    str1[i]
=j;
                    
break;
                }

            }

        }

        
for(i=1;i<=len2;i++)
        
{
            
for(j=0;j<4;j++)
            
{
                
if(str2[i]==b[j])
                
{
                    str2[i]
=j;
                    
break;
                }

            }

        }

        
for(i=0;i<=len1;i++)
        
{
            
for(j=0;j<=len2;j++)
            
{
                
if(i==0&&j==0)a[i][j]=0;
                
else if(j==0&&i>0)a[i][j]=a[i-1][j]+table[str1[i]][4];
                
else if(i==0&&j>0)a[i][j]=a[i][j-1]+table[str2[j]][4];    
                
else
                
{
                    a[i][j]
=a[i-1][j-1]+table[str1[i]][str2[j]];
                    
if(a[i][j]<a[i][j-1]+table[str2[j]][4])a[i][j]=a[i][j-1]+table[str2[j]][4];
                    
if(a[i][j]<a[i-1][j]+table[str1[i]][4])a[i][j]=a[i-1][j]+table[str1[i]][4];
                }

            }

        }

        printf(
"%d\n",a[len1][len2]);
    }

    
return 0;
}

posted @ 2009-05-21 15:02  主函数  阅读(217)  评论(0编辑  收藏  举报