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 71107216 at 2008-08-13 15:56:17 on Problem 2533
#include <iostream>
using namespace std;

int res[1010];
int array[1010];
int mark[1010];
int len;
int func(int index)
{
	if(res[index] >= 0)
		return res[index];
	int max = 0;
	int t;
	for(int i = 0;i < index;i++)
	{
		t = func(i);
		if(array[index] > mark[i])
		{
			t ++;
			if(t > max)
			{
				max = t;
				mark[index] = array[index];
			}
		}
		else
		{
			if(t > max)
			{
				max = t;
				mark[index] = mark[i];
			}
		}
	}
	return res[index] = max;
}
int main()
{
	
	while(scanf("%d",&len) != EOF)
	{
		memset(res,-1,sizeof res);
		for(int i = 0;i < len;i++)
			scanf("%d",&array[i]);
		res[0] = 1;
		mark[0] = array[0];
		printf("%d\n",func(len-1));
		//for(int i = 0;i <= len-1;i++) cout<<mark[i]<<' ';cout<<endl;
		//system("pause");
	}
	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