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

Time Limit Exceed 哪位高人给个好的算法

Posted by faononl at 2004-02-28 17:02:25 on Problem 1040
Source 

#include < iostream.h >
class A
{
public :
	int n,m,l ;
};
int max ;
void big( int last , A *p , int total ,int c ,int a ,int sta[10] )
{
	int i ,j,flag , t ;
	for( i = last ;  i < c ; i++)
	{
		flag = 0 ;
		for( j = p[i].n ; j < p[i].m ; j++ )
			if ( sta[j] + p[i].l > a )
			{
				flag = 1;
				break ;
			}
		if ( flag == 0 )
		{
			for( j = p[i].n ; j < p[i].m ; j++ )
				sta[j]+=p[i].l ;
			t = total + p[i].l * ( p[i].m - p[i].n ) ;
			if ( t > max ) max = t ;
			big( i+1 , p ,t ,c,a ,sta );
            for( j = p[i].n ; j < p[i].m ; j++ )
				sta[j]-=p[i].l ;
		}
	}
}

void main()
{
	int a , b , c , i;
	int sta[8] ;
    A *p ;
	cin >> a >> b >> c ;
	while( c!= 0 || b!= 0 || a!= 0 )
	{
		p = new A[23] ;
		max = 0 ;
		for( i = 0 ; i < 8 ; i++ )
			sta[i] = 0 ;
		for( i = 0 ; i < c ; i++ )
			cin >> p[i].n >> p[i].m >> p[i].l ;
		big( 0 , p, 0 , c , a ,sta);
		cout << max << endl ;
		cin >>  a >> b >> c ;
	}
}



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