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 hcp at 2005-02-03 00:21:40 on Problem 1458
没错啊,典型的dp问题啊,可是总是说wa,我测试了n次,没找到错误啊。盼高人指点

#include <iostream>
#include <cstring>
#define MAX 500
using namespace std;

void main()
{
	int m,n,**c,i,j;
	char a[MAX],b[MAX];
	while(1)
	{
		cin>>a>>b;
		if(cin.eof()==1)
			break;
		m=strlen(a)+1;
		n=strlen(b)+1;
		c=new int*[m];
		for(i=0;i<m;i++)
			c[i]=new int[n];
		for(i=0;i<m;i++)
			c[i][0]=0;
		for(i=0;i<n;i++)
			c[0][i]=0;
		for(i=1;i<m;i++)
			for(j=1;j<n;j++)
			{
				if(a[i-1]==b[j-1])
					c[i][j]=c[i-1][j-1]+1;
				else
					c[i][j]=c[i-1][j]>c[i][j-1]?c[i-1][j]:c[i][j-1];
			}
		cout<<c[m-1][n-1]<<endl;
		for(i=0;i<m;i++)
			delete []c[i];
		delete []c;
	}
}

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