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都超时了 郁闷~~~

Posted by first at 2003-12-28 19:03:55 on Problem 1159
#include <iostream>
using namespace std;
char str[5000];
short cost[3][5000];
int mincost(int i,int j)
{
	if(i==1||i==0)
		return 0;
	else
	{
		if(str[j]==str[j+i-1])
			return cost[(i+1)%3][j+1];
		else
		{   
			int k1=cost[(i+2)%3][j]+1;
		    int k2=cost[(i+2)%3][j+1]+1;
			return (k1>k2?k2:k1);
		}
		
	}
}
void main()
{

	int N;
	scanf("%d %s",&N,str);
    int i,j;
	for(i=0;i<=N;i++)
	 for(j=0;j<=N-i;j++)
	 {
		 cost[i%3][j]=mincost(i,j);
     }
	printf("%d",cost[N%3][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