hdoj 5024 枚举+dfs
来源:互联网 发布:大数据研究内容 编辑:程序博客网 时间:2024/05/17 03:03
hdoj 5024
题意:找一条最长的最多有一个90度拐点的路径,输出长度。
思路:枚举所有点做拐点,dfs最长路径。
#include <cstdio>#include <queue>#include <cstring>#include <algorithm>using namespace std;int d[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, 1, 1, -1, -1, 1, -1, -1, 1};int turn[8][2] = {2, 3, 2, 3, 0, 1, 0, 1, 6, 7, 6, 7, 4, 5, 4, 5};int mx[105][105][8], n;char mp[105][105];int dfs(int x, int y, int dir) { if(mx[x][y][dir] != -1) return mx[x][y][dir]; int ex = x + d[dir][0], ey = y + d[dir][1]; if(ex < 0 || ey < 0 || ex >= n || ey >= n || mp[ex][ey] == '#') return mx[x][y][dir] = 1; return mx[x][y][dir] = 1 + dfs(x + d[dir][0], y + d[dir][1], dir);}int cal(int x, int y, int d1, int d2) { return dfs(x, y, d1) + dfs(x, y, d2) - 1;}main() { while(~scanf("%d", &n) && n) { memset(mx, -1, sizeof mx); int ans = 0; for(int i = 0; i < n; i++) scanf("%s", mp[i]); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++) { if(mp[i][j] == '#') continue; for(int k = 0; k < 8; k++){ ans = max(ans, max(cal(i, j, k, turn[k][0]), cal(i, j, k, turn[k][1]))); } } } printf("%d\n", ans); }}
0 0
- hdoj 5024 枚举+dfs
- HDU/HDOJ 1015(dfs或暴力枚举)
- hdoj-5636===dfs枚举新增的路有木有走
- DFS 枚举
- HDOJ 1796 枚举
- HDOJ 5780 abs(枚举)
- HDOJ 2212 DFS
- hdoj 1016 (dfs)
- hdoj-1242-Rescue(DFS)
- hdoj 1455 Sticks 【dfs】
- hdoj 1518 Square 【dfs】
- hdoj 2212 DFS 【水】
- hdoj 1015 Safecracker 【dfs】
- HDOJ 1015 Safecracker-DFS
- hdoj 1241 【DFS】
- HDOJ Lotto (DFS)
- HDOJ 变形课 (DFS)
- HDOJ Seeding (DFS)
- ORACLE批量更新三种方法比较
- 42. Element hasChildNodes() 方法
- FIS 前端发布打包(入门)
- apt-get切换国内源
- [贪心] poj3040 Allowance
- hdoj 5024 枚举+dfs
- 汉诺塔
- Ubuntu和centos安装vsftpd步骤教程-ftp
- <!DOCTYPE>
- android 广播 实例
- 使用mybatis自带工具,自动生成表对应domain、mapper.xml以及dao
- 出差中
- fatal error C1010: 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include "stdafx.h
- django 学习笔记( 一)