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 |
改成这样就行了: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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator