POJ 1088
来源:互联网 发布:桂正和is知乎 编辑:程序博客网 时间:2024/06/04 01:12
题目大意:中文题
解题思路:dp+dfs。dp保存步数以及标记是否走过。每个位置要去四周找一个比自身大的位置,如果有,位置移动继续判断,如果没有返回的步数为其四周最大的步数多1。
ac代码:
#include <iostream>#include <cstring>#include <algorithm> using namespace std;int map[105][105], dp[105][105], R, C, Max;int dx[4]={-1,1,0,0}, dy[4]={0,0,-1,1};int dfs(int x, int y){if (dp[x][y])return dp[x][y];for (int i=0; i<4; i++){if (x + dx[i] >= 0 && x + dx[i] < R && y + dy[i] >= 0 && y + dy[i] < C&& map[x][y] > map[x+dx[i]][y+dy[i]])dp[x][y] = max(dp[x][y], dfs(x+dx[i], y+dy[i]));}dp[x][y]++;return dp[x][y];}int main(){while (scanf("%d%d", &R, &C)!=EOF){memset(dp, 0, sizeof(dp));for (int i=0; i<R; i++)for (int j=0; j<C; j++)scanf("%d", &map[i][j]);Max = 1;for (int i=0; i<R; i++)for (int j=0; j<C; j++)Max = max(Max, dfs(i, j));printf("%d\n", Max);}return 0;}
阅读全文
0 0
- POJ 1088
- POJ 1088
- poj 1088
- poj 1088
- POJ 1088
- poj 1088
- poj 1088
- poj 1088
- poj 1088
- poj 1088
- poj 1088
- poj--1088
- POJ 1088
- poj 1088
- poj 1088
- POJ 1088
- poj 1088
- POJ 1088
- 水经微图功能简介
- kylin使用中曾遇到的问题整理
- SEO优化知识心得
- jsp前端页面调试快捷键
- springboot jar 后台运行 sh
- POJ 1088
- 让你的代码量减少3倍!使用kotlin开发Android(一) 创建Kotlin工程
- 【二分图最大匹配-匈牙利算法及其优化算法模板】
- Linux的du命令详解
- android studio cMake脚本添加ndk,构建C/C++程序(基础使用篇
- 对原型链的理解
- 解决 sudo ldconfig /sbin/ldconfig.real: xxx 不是符号连接
- unity图像处理(上)
- Fiddler 抓取Iphone / Android数据包