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 |
如果两串最后的字符相同,那么不用考虑在最后加‘——’ 的情况?如果两串最后的字符相同,那么不用考虑在最后加‘——’ 的情况? 看起来是这样子的,但是不会证明 我把AC的动态规划代码里的这段去掉之后就WA(ZOJ里面就算去掉这个条件也是AC) 我随机生成了100个输入,加不加这个条件结果完全一样 请问为什么会WA…… #include<stdio.h> #define MAX 1000 int map[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,-100}}; char gene1[101],gene2[101]; int record[100][100]; int ctn(char c) { switch(c) { case 'A': return 0; case 'C': return 1; case 'G': return 2; case 'T': return 3; case '-': return 4; default: return -1; } } int numget(char a,char b) { int i=ctn(a),j=ctn(b); return map[i][j]; } int max(int a,int b) {return a>b? a:b;} int f(int i,int j) { if(record[i][j]!=MAX)return record[i][j]; if(i==0) { int t=0; for(int k=1;k<=j;k++) t+=numget(gene2[k],'-'); record[i][j]= t; return t; } if(j==0) { int t=0; for(int k=1;k<=i;k++) t+=numget(gene1[k],'-'); record[i][j]= t; return t; } // if(gene1[i]==gene2[j]) // { // record[i][j]=f(i-1,j-1)+numget(gene1[i],gene2[j]); // return record[i][j]; // } int t1,t2,t3; t1=f(i-1,j-1)+numget(gene1[i],gene2[j]), t2=f(i-1,j)+numget(gene1[i],'-'), t3=f(i,j-1)+numget('-',gene2[j]); record[i][j]= max(max(t1,t2),t3); return record[i][j]; } int main() { freopen("in.txt","r",stdin); freopen("out_cr.txt","w",stdout); int times,len1,len2; scanf("%d",×); while(times--) { for(int i=0;i<=100;i++) for(int j=0;j<=100;j++) record[i][j]=MAX; scanf("%d",&len1);getchar(); for(int i=1;i<=len1;i++) { gene1[i]=getchar(); if(ctn(gene1[i])==-1)i=-1; } scanf("%d",&len2);getchar(); for(int i=1;i<=len2;i++) { gene2[i]=getchar(); if(ctn(gene2[i])==-1)i=-1; } printf("%d\n",f(len1,len2)); } } 就是被//注释掉的那段代码 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator