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:学渣瞎写的代码 不知道是不是用例太水 反正过了 递归In Reply To:学渣瞎写的代码 不知道是不是用例太水 反正过了 递归 Posted by:814264306 at 2019-07-05 10:02:54 > #include<iostream> > using namespace std; > int r, c; > int map[110][110]; > int vis[110][110]; > int dr[4][2] = { 1,0, -1,0, 0,1, 0,-1 }; > int dfs(int x,int y) { > if (vis[x][y] != 0) { > return vis[x][y]; > } > int temp = 0; > for (int i = 0; i < 4; i++) { > int x0 = x + dr[i][0]; > int y0 = y + dr[i][1]; > if (x0 > r || x0<1 || y0>c || y0 < 1)continue; > if (map[x0][y0] >= map[x][y])continue; > if (temp < dfs(x0, y0)) { > temp = dfs(x0, y0); > } > } > vis[x][y] = 1 + temp; > return 1 + temp; > } > > int main() { > cin >> r >> c; > for (int i = 0; i < 110; i++) { > for (int j = 0; j < 110; j++) { > vis[i][j] = 0; > } > } > //获取地图数据 > for (int i = 1; i <= r; i++) { > for (int j = 1; j <= c; j++) { > cin >> map[i][j]; > } > } > //开始处理 > int ans = -1; > for (int i = 1; i <= r; i++) { > for (int j = 1; j <= c; j++) { > vis[i][j] = dfs(i, j); > if (ans < vis[i][j])ans = vis[i][j]; > if (ans == r*c) { > break; > } > } > if (ans == r*c) { > break; > } > } > cout << ans<<endl; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator