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

可能是没有用临时数组的原因吧

Posted by astropeak at 2011-05-11 11:42:37 on Problem 1040
In Reply To:Re:我没有剪枝啊,直接回溯,800MSAC。。。。 Posted by:yzhw at 2009-05-07 17:28:13
> # include <stdio.h>
> typedef struct point 
> {
>   int price;
>   int p;
>   int s;
>   int e;
> }sta;
> sta data[23];  
> int station[8];
> int maxnum,stanum,ticnum;
> int tres,res;
> check(int s)
> {
>  int i;
>  for(i=data[s].s;i<data[s].e;i++)
>    if(station[i]+data[s].p>maxnum) return 0;
>  return 1;
> }
> void deal(int s)
> {
>  if(s>ticnum&&tres>res) res=tres;
>  else if(s>ticnum) return;
>  else
>  {
>      int i;
>      if(check(s))
>      {
>       for(i=data[s].s;i<data[s].e;i++) station[i]+=data[s].p;
>       tres+=data[s].price;
>       deal(s+1);
>       for(i=data[s].s;i<data[s].e;i++) station[i]-=data[s].p;
>       tres-=data[s].price;
>      }
>      deal(s+1);
>  }
> }
>  
> int main()
> {
> 
>     while(1)
>     {
>       int i,j,totalp=0; 
>       memset(station,0,sizeof(station));
>       scanf("%d %d %d",&maxnum,&stanum,&ticnum);
>       if(!maxnum&&!stanum&&!ticnum) break;
>       for(i=1;i<=ticnum;i++)
>       {
>        scanf("%d %d %d",&data[i].s,&data[i].e,&data[i].p);
>        data[i].price=data[i].p*(data[i].e-data[i].s);
>       }
>        res=tres=0;
>        deal(1);
>        
>        printf("%d\n",res);
>      }
>    
>      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