POJ 1154 解题报告
来源:互联网 发布:电子乐器软件 编辑:程序博客网 时间:2024/04/29 07:34
这道题是普通的DFS,不需要优化就可以通过。
thestoryofsnow1154Accepted164K32MSC++1326B/* ID: thestor1 LANG: C++ TASK: poj1154 */#include <iostream>#include <fstream>#include <cmath>#include <cstdio>#include <cstring>#include <limits>#include <string>#include <vector>#include <list>#include <set>#include <map>#include <queue>#include <stack>#include <algorithm>#include <cassert>using namespace std;const int MAXR = 20;// There is '\0' in the endconst int MAXC = 20 + 1;int neighbors[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};void dfs(char board[][MAXC], int r, int c, const int R, const int C, bool visited[], int p, int &maxp) {int i = board[r][c] - 'A';if (visited[i]) {return;}visited[i] = true;p++;if (p > maxp) {maxp = p;}for (int d = 0; d < 4; ++d) {int nr = r + neighbors[d][0];int nc = c + neighbors[d][1];if (0 <= nr && nr < R && 0 <= nc && nc < C) {dfs(board, nr, nc, R, C, visited, p, maxp);}}visited[i] = false;}int main(){char board[MAXR][MAXC];int R, C;scanf("%d%d", &R, &C);for (int r = 0; r < R; ++r) {scanf("%s", board[r]);}// printf("[debug]board:\n");// for (int r = 0; r < R; ++r) {// printf("[%s]\n", board[r]);// }bool visited[26];for (int i = 0; i < 26; ++i) {visited[i] = false;}int maxp = 0;dfs(board, 0, 0, R, C, visited, 0, maxp);printf("%d\n", maxp);return 0;}
0 0
- POJ 1154 解题报告
- poj数百篇解题报告
- poj 1141解题报告
- poj 1001解题报告
- poj 1011 解题报告
- poj 1087 解题报告
- poj 2153解题报告
- poj 2051解题报告
- POJ 1167 解题报告
- poj 1026 解题报告
- POJ 1077 解题报告
- POJ 1042 解题报告
- POJ 1095 解题报告
- POJ 1159解题报告
- poj 2312解题报告
- POJ 1001解题报告
- POJ 1002解题报告
- POJ 1006解题报告
- iOS swift-GCD-队列组
- 54. Spiral Matrix
- web页面中盒子的运用
- 【USACO题库】5.5.2 Hidden Password隐藏口令
- sklearn 源码解析 基本线性模型 岭回归 ridge.py(1)
- POJ 1154 解题报告
- [美剧赏析] 权力的游戏<Game of Thrones>完全赏析 (序)
- Java:单例模式的七种写法
- 数据结构之树状数组
- 非常实用全面的 C++框架,库类等资源
- 有一磁盘文件"employee",内存放职工的数据。
- Random Walk 挑战程序设计竞赛 期望值和方程组
- java面试中常用的排序算法
- 【QA测试技术研究】性能测试场景设计--混合业务场景下的脚本比例控制