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

3个滚动数组才行

Posted by gzh1992n at 2013-04-24 16:21:02 on Problem 1159
In Reply To:如此的滚动,为什么都是WC Posted by:smzzw at 2013-01-22 15:28:19
unsigned short dp[3][N];
char buf[N];
int main()
{
	int n,s,e,x,y,z;
	scanf("%d",&n);
	getchar();
	gets(buf);
	for(int i=1;i<n;i++){
		for(int j=0;j+i<n;j++){
			s=j,e=j+i;
			x=i%3,y=(i+2)%3,z=(i+1)%3;
			if(buf[s]==buf[e]) dp[x][s]=dp[z][s+1];
			else dp[x][s]=min(dp[y][s+1]+1,dp[y][s]+1);
		}
	}
	printf("%d\n",dp[x][0]);
	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