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 hitrose at 2010-10-25 19:42:56 on Problem 1458
#include <stdio.h>

unsigned char DP[2][251];

char str1[251],str2[251];
int main()
{
	unsigned char i,j,n,m;
	while (scanf("%s%s",str1,str2)!=EOF)
	{	
		for( i = 0;i<2;++i)
			for(j = 0;j<252;++j)
				DP[i][j] = 0;
		for(m = 0;str1[m];++m);
		for(n = 0;str2[n];++n);
		for(i =1;i<=m;++i)
		{
			for(j =1;j<=n;++j)
			{
				if(str1[i-1] == str2[j-1])
					DP[i%2][j] = DP[(i-1)%2][j-1]+1;
				else if(DP[(i-1)%2][j]>DP[i%2][j-1])
					DP[i%2][j] = DP[(i-1)%2][j];
				else DP[i%2][j] = DP[i%2][j-1];
			}
		}
		printf("%d\n",DP[m%2][n]);
	}
	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