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 |
大牛们,HELP请问为什么WA呢?谢谢 #include <stdio.h> #include <string.h> #include <math.h> int tem,tem1,n,i,an[1002],dp[1002][1002],kth=1; bool used[1002][1002]; int work(int x , int y) { if(!used[x][y]) { used[x][y] = true; if(y-x == 1) dp[x][y] = abs(an[y] - an[x]) ; else { if(an[x+1] >= an[y]) tem = work(x+2,y) + an[x] -an[x+1]; else tem = work(x+1,y-1) + an[x] -an[y]; if(an[x] >= an[y-1]) tem1 = work(x+1,y-1) + an[y] - an[x]; else tem1 = work(x , y-2) + an[y] - an[y-1]; if(tem>tem1) dp[x][y] = tem; else dp[x][y] = tem1; } } return dp[x][y]; } int main() { while(scanf("%d",&n) && n) { memset(used,0,sizeof(used)); for(i = 0 ; i < n ; i++) scanf("%d",an+i); printf("In game %d, the greedy strategy might lose by as many as %d points.\n",kth++,work(0,n-1)); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator