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 |
怎么总超时啊!! 哪位牛人帮我看看怎么改啊#include <iostream> using namespace std; int r,c,s=0; char b[21][21]; int a[30]; int step(int x, int y) { int max = 0; a[b[x][y]-65]=0; if (a[b[x][y-1]-65]&&y>=1) { if (max < step(x, y-1)) { max = step(x, y-1); } } if (a[b[x][y+1]-65]&&y<c-1) { if (max < step(x, y+1)) { max = step(x, y+1); } } if (a[b[x-1][y]-65]&&x>=1) { if (max < step(x-1, y)) { max = step(x-1, y); } } if (a[b[x+1][y]-65]&&x<r-1) { if (max < step(x+1, y)) { max = step(x+1, y); } } a[b[x][y]-65]=1; return s=max+1; } int main() { int x,y,q=0; cin>>r>>c; memset (a,1,sizeof (a)); for(x=0;x<r;x++) for(y=0;y<c;y++) { cin>>b[x][y]; } step(0,0); printf("%d\n",s); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator