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

最水dpMLE 改成short AC

Posted by songruirui at 2013-03-13 16:32:51 on Problem 1159
#include <iostream>
#include <memory.h>
using namespace std;
short dp[5001][5001];
int min(int a,int b)
{
	if(a<=b)
		return a;
	else
		return b;
}
int main()
{
	char str[5001];
	int num;
	
	cin>>num;
	for(int i=1;i<=num;i++)
		cin>>str[i];
	//初始化
	for(int i=1;i<=num;i++)
	{
		dp[0][i]=num-i+1;
	}
	for(int i=1;i<=num;i++)
	{
		dp[i][num+1]=i;
	}
	for(int i=1;i<=num;i++)
	{
		for(int j=num;j>=i;j--)
		{
			if(str[i]==str[j])
				dp[i][j]=dp[i-1][j+1];
			else
				dp[i][j]=9999;
			dp[i][j]=min(dp[i][j],dp[i-1][j]+1);
			dp[i][j]=min(dp[i][j],dp[i][j+1]+1);
		}
	}
	int minnum=32766;
	for(int i=1;i<=num;i++)
	{
		minnum=min(dp[i][i+1],minnum);
		minnum=min(minnum,dp[i][i]);
	}
		
	
	cout<<minnum;
	//system("pause");
}

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