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 |
Re:高手帮忙啊! 那组经典数据都过了 还是WA啊啊啊啊啊啊In Reply To:高手帮忙啊! 那组经典数据都过了 还是WA啊啊啊啊啊啊 Posted by:ysj16 at 2010-03-02 21:30:04 你好,你的int max(int n,int m)函数里有一个细节问题。 if(arr[n+1][m]<arr[n][m] && arr[n+1][m]>=0) if(max(n+1,m)>amax) amax=rec[n+1][m]; 改成下面ac了。原因不是很了解~ if(arr[n+1][m]<arr[n][m] && arr[n+1][m]>=0) if(max(n+1,m)>amax) amax=max(n+1,m); > #include<stdio.h> > #include<string.h> > int arr[110][110]; > int rec[110][110]; > int main() > { > int max(int,int); > int i,j,bmax; > int r,c; > scanf("%d %d",&r,&c); > > for(i=0;i<110;i++) > for(j=0;j<110;j++) > { > arr[i][j]=-1; > rec[i][j]=-1; > } > > bmax=0; > for(i=1;i<=r;i++) > for(j=1;j<=c;j++) > scanf("%d",&arr[i][j]); > for(i=1;i<=r;i++) > for(j=1;j<=c;j++) > { > if(max(i,j)>bmax) > bmax=rec[i][j]; > } > printf("%d\n",bmax); > return 0; > > } > int max(int n,int m) > { > int amax=0; > if(arr[n][m]<=arr[n+1][m]&&arr[n][m]<=arr[n-1][m]&&arr[n][m]<=arr[n][m+1]&&arr[n][m]<=arr[n][m-1]) > return 1; > if(rec[n][m]!=-1) return rec[n][m]; > if(arr[n+1][m]<arr[n][m] && arr[n+1][m]>=0) > if(max(n+1,m)>amax) > amax=rec[n+1][m]; > if(arr[n-1][m]<arr[n][m] && arr[n-1][m]>=0) > if(max(n-1,m)>amax) > amax=rec[n-1][m]; > if(arr[n][m+1]<arr[n][m] && arr[n][m+1]>=0) > if(max(n,m+1)>amax) > amax=rec[n][m+1]; > if(arr[n][m-1]<arr[n][m] && arr[n][m-1]>=0) > if(max(n,m-1)>amax) > amax=rec[n][m-1]; > rec[n][m]=amax+1; > return amax+1; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator