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

1458求解..编译不过

Posted by Magic_M at 2011-07-20 09:23:12 on Problem 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:
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