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

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

Posted by jfzhang at 2013-09-18 11:39:05 on Problem 1159
In Reply To:为什么dp数组定义在函数里面就RE,定义成全局变量就AC了 Posted by:sdlllichao at 2013-09-18 09:45:24
c语言的问题吧,全局变量是存放在堆里面的,函数内的变量是存放在栈里面的,栈的容量远远小于堆

> #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