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

为什么dp数组定义在函数里面就RE,定义成全局变量就AC了

Posted by sdlllichao at 2013-09-18 09:45:24 on Problem 1159
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 5002
using namespace std;
short dp[N][N];
int main()
{
	int n;
	while(cin>>n)
	{
		char *str1=new char[n+1];
		char *str2=new char[n+1];
		cin>>str1;
		int i,j;
		for(i=0;i<n;i++)
			str2[i]=str1[n-i-1];
		str2[i]='\0';
		memset(dp,0,sizeof(dp));
		for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
				if(str1[i]==str2[j])
					dp[i+1][j+1]=dp[i][j]+1;
				else
					dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
			}
		}
		cout<<n-dp[n][n]<<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