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

WA的人来看看这组简单数据

Posted by temp_ptr at 2011-10-07 14:19:34 on Problem 1952
6
4 3 4 1 3 1

======
答案应该是3 1,最长长度为3,只有一种情况:4,3,1,我也是计数计了好久都没找到正确的方法计正确。网上找到了一个很简洁的方法,下面是我AC的代码,我是从右到左算最大升序列

#include <iostream>
#include <fstream>
using namespace std;
const int N = 5001;
int n, dp_len[N], a[N], ans_len, dp_time[N],ans_time;

int main()
{
	fstream fin("1952.txt");
	fin>>n;
	for(int i = 1; i <= n; i++)
		fin>>a[i];
	ans_len = 1; dp_len[n] = 1; dp_time[n] = 1;
	for(int i = n-1; i >= 1; i--)
	{
		dp_len[i] = 1; dp_time[i] = 1;
		for(int j = i+1; j <= n; j++)
			if(a[i] > a[j])
			{
				if(dp_len[j] + 1 > dp_len[i])
				{
					dp_len[i] = dp_len[j]+1; dp_time[i] = dp_time[j];
				}
				else if(dp_len[j]+1 == dp_len[i])
					dp_time[i] += dp_time[j];
			}
			else if(a[i] == a[j])//key point!
			{
				if(dp_len[i] == 1)
					dp_time[i] = 0;
				break;
			}
	///////////////////////////
		if(dp_len[i] > ans_len)
			ans_len = dp_len[i];
	}
	///////////////////////////
	ans_time = 0;
	for(int i = 1; i <= n; i++)
		if(dp_len[i] == ans_len)
			ans_time += dp_time[i];
	cout<<ans_len<<" "<<ans_time<<endl;
	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