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 |
又见WA !!!谁能救救我啊,指点一下吧#include <iostream> using namespace std; #define max(a, b) ((a > b) ? (a) : (b)) const int N =5001; short dp[N][2]; int main () { char c[N], rc[N]; while(scanf("%s%s", c+1, rc+1) != EOF) { int maxi = 0; int k = strlen(c), l = strlen(rc), s; s = l; for(int j = 0; j < 2; j++) { for(int i = 0; i < N; i++) dp[i][j] = 0; } for(int j = 1; s > 0; j++) { for(int i = 1; i < k; i++) { if(rc[j] == c[i]) dp[i][(j+2)%2] = dp[i-1][(j+1)%2] + 1; else if(dp[i-1][(j+2)%2] > dp[i][(j+1)%2]) dp[i][(j+2)%2] = dp[i-1][(j+2)%2]; else dp[i][(j+2)%2] = dp[i][(j+1)%2]; maxi = max(dp[i][(j+2)%2], maxi); } s--; } cout << maxi << 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