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 zhouhaiwei at 2006-08-07 18:48:22 on Problem 1952
#include<iostream.h>
int main()
{
	int n,i,j,max,sum,dmax;
	cin>>n;
	int *a=new int [n+1];
	int *b=new int [n+1];
	int *c=new int [n+1];
	for(i=0;i<n;i++)
		c[i]=0;
	for(i=0;i<n;i++)
		cin>>a[i];
	max=0;
	for(i=0;i<n;i++)
	{
		b[i]=1;
		for(j=0;j<i;j++)
		{
			if(a[j]>a[i])
				if(b[j]+1>b[i])
					b[i]=b[j]+1;
			if(b[i]>max)
				max=b[i];
		}
		dmax=-1;
		for(j=0;j<i;j++)
		{
			if(a[j]>a[i]&&b[i]==b[j]+1)
				if(c[j]==0)
				{
					if(a[j]!=dmax)
					{
						c[i]++;
						dmax=a[j];
					}
				}
				else
				{
					if(a[j]!=dmax)
					{
						c[i]+=c[j];
						dmax=a[j];
					}
				}
		}
	}
	int count=0;
	sum=0;
	int dm=-1;
	for(i=0;i<n;i++)
	{
		if(b[i]==max&&a[i]!=dm)
		{
			sum+=c[i];
			dm=a[i];
		}
	}
	if(n==1)
	{
		max=sum=1;
		cout<<max<<" "<<sum<<endl;
	}
	else{
	cout<<max<<" ";
	dm=-1;
	if(sum==0)
	{
		for(i=0;i<n;i++)
		{
			if(a[i]!=dm)
			{
				sum++;
				dm=a[i];
			}
		}
		cout<<sum<<endl;
	}
	else
		cout<<sum<<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