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 |
poj1088 Time Limit Exceeded一直提示这个,谁能给点提示,哪里的问题啊?谢谢了 代码: #include <stdio.h> int findroad(int (*R)[102], int r, int c, int i, int j) { int ret = 1; int tmp = 1; int max = 0; int cu = R[i][j]; //当前元素 int t = R[i-1][j]; //上面 int b = R[i+1][j]; //下面 int l = R[i][j-1]; //左面 int re = R[i][j+1]; //右面 if (t < cu && t != 0) { tmp = findroad(R, r, c, i - 1, j); if (tmp > max) max = tmp; } if (b < cu && b != 0) { tmp = findroad(R, r, c, i + 1, j); if (tmp > max) max = tmp; } if (l < cu && l != 0) { tmp = findroad(R, r, c, i, j - 1); if (tmp > max) max = tmp; } if (re < cu && re != 0) { tmp = findroad(R, r, c, i, j + 1); if (tmp > max) max = tmp; } ret += max; return ret; } int main(int argc, char **argv) { int R[102][102] = {0}; int r, c, i, j; int ret; int tmp; if (!scanf("%d %d", &r, &c)) return -1; for (i = 1; i <= r; i++) { for (j = 1; j <= c; j++) { if (!scanf("%d", &R[i][j])) return -1; } } ret = 0; for (i = 1; i <= r; i++) { for (j = 1; j <= c; j++) { tmp = findroad(R, r, c, i, j); if (tmp > ret) ret = tmp; } } printf("%d\n", ret); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator