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

贴个简单的滚动数组。。。

Posted by 0943041192 at 2011-02-14 01:52:02 on Problem 1159
#include <iostream>
#include <cstdlib>
#include <algorithm>
#define N 5010
#define REP(i,n)	for(i=0;i<n;i++)

using namespace std;

int main()
{
	int i,j,k,n;
	cin>>n;
	char a[N],b[N];
	scanf("%s",a);
	REP(i,n)	b[i] = a[i];
	reverse(a,a+n);
	short dp[2][N];
	REP(i,n)
	{
		dp[0][i] = 0;
		dp[1][i] = 0;
	}
	REP(i,n)
	{
		REP(j,n)
		{
			if( a[i] == b[j] )
				dp[(i+1)%2][j+1] = dp[i%2][j]+1;
			else
			{
				dp[(i+1)%2][j+1] = dp[i%2][j+1];
				if( dp[(i+1)%2][j+1] < dp[(i+1)%2][j] )
					dp[(i+1)%2][j+1] = dp[(i+1)%2][j];
			}
		}
	}
	cout<<n-dp[n%2][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