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 |
1458求解..编译不过#include <iostream> #include <cstdio> #include <cstring> using namespace std; #define max(a,b) ((a)>(b):(a)?(b)) char code[1005],code1[1005]; int dp[1005][1005]; int main() { while(scanf("%s%s",code,code1)==2) { int i,j; memset(dp,0,sizeof(dp)); int n=strlen(code); int m=strlen(code1); for(i=0;i<n;i++) for(j=0;j<m;j++) { if(code[i]==code1[j]) { if(i>=1&&j>=1) { dp[i][j]=dp[i-1][j-1]+1; dp[i][j]=max(dp[i][j],dp[i-1][j]); dp[i][j]=max(dp[i][j],dp[i][j-1]); } else dp[i][j]=1; } else { if(i>=1&&j>=1)dp[i][j]=max(dp[i][j-1],dp[i-1][j]); else if(i>=1)dp[i][j]=max(dp[i][j],dp[i-1][j]); else if(j>=1)dp[i][j]=max(dp[i][j],dp[i][j-1]); else dp[i][j]=0; } } cout<<dp[n-1][m-1]<<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