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 cuiaoxiang at 2007-10-12 13:09:19 on Problem 3056
In Reply To:偶滴潮湿代码 Posted by:cuiaoxiang at 2007-10-12 12:26:12
Source

Problem: 3056  User: cuiaoxiang 
Memory: N/A  Time: N/A
Language: G++  Result: Time Limit Exceeded

Source 
#include <iostream>

using namespace std;

const int N = 1000 + 10;
int dp[N][N];
int a[N];

int run(int s, int t)
{
	if (dp[s][t] != -1) return dp[s][t];
	int &ret = dp[s][t];
	int i;
	ret = 0;
	for (i = s + 1; i < t; i += 2)
		ret = max(ret, run(s + 1, i) + run(i + 1, t) + (a[s] == a[i] ? 1 : 0));
	return ret;
}

int main()
{
	int casenum, i, n;
	scanf("%d", &casenum);
	while (casenum--)
	{
		scanf("%d", &n);
		for (i = 0; i < n; ++i) scanf("%d", a + i);
		memset(dp, 255, sizeof(dp));
		printf("%d\n", run(0, 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