Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:一道用dp 做的题,有兴趣的来看看!In Reply To:一道用dp 做的题,有兴趣的来看看! Posted by:wangbaobao at 2009-05-01 13:57:45 我也是用dp做的,但为什么总是WA呢,高手帮忙看看。。。 #include<stdio.h> #include<string.h> int sf(char a,char b) { if(a==b) return 5; if((a=='A'&&b=='C')||(a=='C'&&b=='A')) return -1; if((a=='A'&&b=='G')||(a=='G'&&b=='A')) return -2; if((a=='A'&&b=='T')||(a=='T'&&b=='A')) return -1; if((a=='A'&&b=='-')||(a=='-'&&b=='A')) return -3; if((a=='C'&&b=='G')||(a=='G'&&b=='C')) return -3; if((a=='C'&&b=='T')||(a=='T'&&b=='C')) return -2; if((a=='C'&&b=='-')||(a=='-'&&b=='C')) return -4; if((a=='G'&&b=='T')||(a=='T'&&b=='G')) return -2; if((a=='G'&&b=='-')||(a=='-'&&b=='G')) return -2; if((a=='T'&&b=='-')||(a=='-'&&b=='T')) return -1; } int max(int i,int j,int k) { if(i>j) j = i; if(j>k) k = j; return k; } int main() { int t; scanf("%d",&t); char a[105],b[105]; int la,lb; int sc[105][105]; int i,j; while(t--){ memset(sc,0,sizeof(sc)); scanf("%d %s",&la,a); scanf("%d %s",&lb,b); sc[0][0] = 0; for(i=1;i<=la;i++) sc[i][0] = sf(a[i-1],'-'); for(i=1;i<=lb;i++) sc[0][i] = sf(b[i-1],'-'); for(i=1;i<=la;i++){ for(j=1;j<=lb;j++){ sc[i][j] = max( sc[i-1][j]+sf(a[i-1],'-'),sc[i][j-1]+sf('-',b[j-1]),sc[i-1][j-1]+sf(b[j-1],a[i-1]) ); } } printf("%d\n",sc[la][lb]); } return 0 ; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator