1048
来源:互联网 发布:windows phone 微信 编辑:程序博客网 时间:2024/06/07 17:04
#include<stdio.h> #include<iostream> #define DEBUG_IO (0) #define DEBUG (0) using namespace std; const int N = 52; struct Node { int val; int step; }; int n; int step; int temp; Node map[N][N]; bool vis[N][N]; void dfs(int x, int y, int prev); int main() { #if DEBUG freopen("input.txt", "r", stdin); setbuf(stdout, NULL); #endif int i, j, k; scanf("%d", &n); for(i = 0; i < n; i++) { for(j = 0; j < n; j++) { scanf("%d", &map[i][j].val); vis[i][j] = 0; map[i][j].step = -1; } } for(i = 0; i < n; i++) { for(j = 0; j < n; j++) { if(map[i][j].step != -1) { continue; } step = 0; temp = 0; vis[i][j] = 1; #if DEBUG_IO cout<<"("<<i<<","<<j<<","<<step<<")"; #endif dfs(i+1, j, map[i][j].val); dfs(i-1, j, map[i][j].val); dfs(i, j+1, map[i][j].val); dfs(i, j-1, map[i][j].val); #if DEBUG_IO cout<<"step = "<<step<<endl; #endif map[i][j].step = step; vis[i][j] = 0; } } for(i = 0; i < n; i++) { for(j = 0; j < n; j++) { if(step < map[i][j].step) { step = map[i][j].step; } } } printf("%d", step+1); return 0; } void dfs(int x, int y, int prev) { if(x >= 0 && x < n && y >= 0 && y < n && vis[x][y] == 0) { vis[x][y] = 1; if(prev > map[x][y].val) { temp++; if(map[x][y].step != -1) { if(step < temp + map[x][y].step) { step = temp + map[x][y].step; } //RETURN 之前记得重置 vis[x][y] = 0; temp--; #if DEBUG_IO cout<<"("<<x<<","<<y<<","<<step<<")"; #endif return; } if(step < temp) { step = temp; } #if DEBUG_IO cout<<"("<<x<<","<<y<<","<<step<<")"; #endif dfs(x+1, y, map[x][y].val); dfs(x-1, y, map[x][y].val); dfs(x, y-1, map[x][y].val); dfs(x, y+1, map[x][y].val); temp--; } vis[x][y] = 0; } } /************************************************************** Problem: 1048 User: xxxx Language: C++ Result: 正确 Time:10 ms Memory:484 kb ****************************************************************/
0 0
- 1048
- 1048
- 1048
- 1048
- 1048
- 1048
- 1048
- ZOJ1045&&1048
- 1048 Inverso
- NIT 1048
- zoj 1048
- HDU 1048
- hdu 1048
- hdu 1048
- hdu 1048
- 1048 Inverso
- PAT 1048
- hdu 1048
- 隐藏导航栏时添加在self.view上的Tableview位置产生20个单位的误差
- ibatis+struts+spring配置和登录实现
- android字体样式图文混排
- day01
- basic_string::append
- 1048
- 前缀中缀后缀表达式
- AndroidMaterialDesign动画之Curved Motion
- 杭州嘉云数据电话面试
- android实现在Edittext中把部分字符隐藏
- ClassLoader的理解
- 网站设计
- hadoop2.x常用端口及定义方法
- 项目中遇到的HQL查询问题