Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

又见WA !!!谁能救救我啊,指点一下吧

Posted by 501820158 at 2011-08-05 10:30:10 on Problem 1458
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator