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了。这个破Judge也不告诉你是什么Test Case上出错了,真郁闷!

Posted by cuckoo at 2007-06-29 20:05:23 on Problem 2127
#include <algorithm>
using namespace std;
#include <stdio.h>

int lcis(int a[], int m, int b[], int n, int c[])
{
	int lcis[512]={0};
	int pi[512]={-1};

	for(int i=0; i<m; i++)
	{
		int k=-1;
		for(int j=0; j<n; j++)
		{
			if(b[j]<a[i])
			{
				if(k==-1 || lcis[j]>lcis[k]) k=j;
			}
			else if(a[i]==b[j])
			{
				int t= (k>=0) ? 1+lcis[k] : 1;
				if(t>lcis[j])
				{
					lcis[j]=t;
					pi[j]=k;
				}
			}
		}
	} 

	int idx=(int)(max_element(lcis, lcis+n)-lcis);

	int l=lcis[idx];

	for(int p=idx, k=l-1; k>=0 && p>=0; p=pi[p], k--) c[k]=b[p];

	return l;
}

int main()
{
	int a[512]={0};
	int b[512]={0};
	int c[512]={0};
	int m=0, n=0, l=0;

	scanf("%d", &m);
	for(int i=0; i<m; i++) scanf("%d", a+i);

	scanf("%d", &n);
	for(int j=0; j<n; j++) scanf("%d", b+j);

	l=lcis(a, m, b, n, c);

	printf("%d\n", l);
	for(int k=0; k<l; k++) printf("%d ", c[k]);
	printf("\n"); 

	return 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