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 xym_sun at 2012-11-27 19:54:31 on Problem 2127
我用的是n^3的算法。
期中第三层循环是这样的。
大家看下面这两种方法,我开始用的是第一种,但输出错误,然后上网找了一下,别人用的是第二种,
可是我觉得我和他的是一样的呀,只不过他是先找到dp[i-1][k]中的最大项,然后再判断,我是边判断边寻找,但我觉得一样的呀?

//第一种
if(num1[i]==num2[j])
{
	for(int k=1; k<j; k++)
	{

		if(num2[j]>num2[k]&&dp[i-1][k]+1>dp[i][j])
		{
			dp[i][j] = dp[i-1][k]+1;
		}
	}
}

//第二种
if(num1[i]==num2[j])
{
	int p=0;
	for(int k=1; k<j; k++)
		if(num2[j]>num2[k]&&dp[i-1][k]>dp[i-1][p])
			p=k;
	if(dp[i-1][p]+1>dp[i][j])
	{
		dp[i][j]=dp[i-1][p]+1;
	}
}

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