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

一直TLE,请高手赐教!!!

Posted by hubo at 2008-07-18 19:51:38 on Problem 2626
//2626
#include <iostream>
using namespace std;
typedef struct node
{ 
   int w,b;       
}p;
p play[2000];
int playN;
int value[100][100][2000];
bool f[100][100][2000]; //记录是否计算过 

int max(int a, int b, int c)
{
   if(a > b)
     {
       return a>c ? a : c ;   
     } 
   
   return b>c ? b : c ;        
}

//dp_play(w,b,num)表示在num个选手中选择w个b棋手,b个黑棋手所能达到的最大value值 
int dp_play(int w,int b,int num)
{
    if(w<0 || b<0 || num<1)
		return 0; 
	if(f[w][b][num])
     {
       return value[w][b][num] ;              
     }
     
   if(num==1)
     {
        if(w==1) 
          { 
             f[1][0][1]=1;
             value[1][0][1]=play[1].w; 
             return play[1].w; 
          }
        if(b==1) 
          { 
             f[0][1][1]=1;
             value[0][1][1]=play[1].b;     
             return play[1].b; 
          }
          
        f[0][0][1]=1;
        value[0][0][1]=0;        
        return 0;      
     }
   
   f[w][b][num]=1;
   value[w][b][num]=max( dp_play(w-1,b,num-1) + play[num].w, dp_play(w,b-1,num-1) + play[num].b, dp_play(w,b,num-1) ); 
   
   return  value[w][b][num];
      
} 

int main(void)
{ 
   int white,black,i=1;
   
   while( scanf("%d %d",&white,&black) )
     {
       play[i].w=white;            
       play[i].b=black;          
       i++;  
     }   
   playN=i-1;

   printf( "%d", dp_play(15,15,playN) ); 
   system("pause");
   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