| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Time Limit Exceed 哪位高人给个好的算法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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator