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:晕,这代码咋过不到哦??In Reply To:Re:晕,这代码咋过不到哦?? Posted by:810974380 at 2009-07-28 17:21:41 我的 给你看下 #include<iostream> #include<cstring> using namespace std; int lcs(char *a,char *b) { int m=strlen(a)-1;int n=strlen(b)-1; int i,j,k,l,p[500][500]; for( i=0;i<=m;i++) p[i][0]=0; for( j=0;j<=n;j++) p[0][j]=0; for( k=0;k<=m;k++) { for( l=0;l<=n;l++) if(a[k]==b[l]) p[k+1][l+1]=p[k][l]+1; else if(p[k+1][l]>=p[k][l+1]) p[k+1][l+1]=p[k+1][l]; else p[k+1][l+1]=p[k][l+1]; } return p[m+1][n+1]; } int main() { char m[500],n[500]; while(cin>>m>>n) cout<<lcs(m,n)<<endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator