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 sza at 2006-02-23 23:16:07 on Problem 2738
In Reply To:太可耻了,居然企图用递归过…… Posted by:adamgic at 2005-12-23 05:11:07
int result[1001][1001]
int DP(int card[],int start,int end,int result[][1001])
{
    int a,b,c,d;
    if(start+1==end) return max(card[start],card[end]);
    else if(result[start][end]!=0) return result[start][end]; /*instead of recursion*/
    
    if(card[start+1]>=card[end]){a=start+2;b=end;}
    else {a=start+1;b=end-1;}
    if(card[start]>=card[end-1]){c=start+1,d=end-1;}
    else {c=start;d=end-2;}
    result[start][end]=max(card[start]+DP(card,a,b,result),DP(card,c,d,result)+card[end]);
}

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