poj1088(記憶化搜索)
2024-09-29 18:02:58
題目鏈接:http://poj.org/problem?id=1088
題意:中文題誒~
思路:dfs,不過直接dfs因該會超時,那我們給他加個記錄路徑就好了...
代碼:
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std; const int MAXN=1e2+;
int dp[MAXN][MAXN], mp[MAXN][MAXN];
int dir[][]={, , , -, , , -, };
int n, m, fx, fy; int dfs(int x, int y){
if(dp[x][y]) return dp[x][y];
for(int i=; i<; i++){
fx=x+dir[i][];
fy=y+dir[i][];
if(fx>=&&fx<n&&fy>=&&fy<m){
if(mp[fx][fy]<mp[x][y]){
int cnt=dfs(fx, fy);
if(dp[x][y]<cnt+){
dp[x][y]=cnt+;
}
}
}
}
return dp[x][y];
} int main(void){
while(cin >> n >> m){
int ans=;
memset(dp, , sizeof(dp));
for(int i=; i<n; i++){
for(int j=; j<m; j++){
cin >> mp[i][j];
}
}
for(int i=; i<n; i++){
for(int j=; j<m; j++){
int cnt=dfs(i, j);
ans=max(ans, cnt);
}
}
cout << ans+ << endl;
}
return ;
}
最新文章
- 使用MATLAB对图像处理的几种方法(上)
- plist文件的读取和xib加载cell
- GUID 全局统一标识符的介绍
- python代码编程规范
- [原创]谷歌插件 - YE搜图助手(YeImageFinder)
- Android Service AIDL 远程调用服务 【简单音乐播放实例】
- JS浮点类型计算
- Oracle EBS-SQL (WIP-4):检查检查成品标准作业是否勾选";固定";标识.sql
- LeetCode OJ 82. Remove Duplicates from Sorted List II
- android AlarmManager讲解
- 单片机stm32小白入门级学习路线“图”
- Exploit-Exercises nebule 旅行日志(三)
- SqlServer误删数据恢复
- Visual Studio 2015编译Lua 5.3.4遇到的坑
- genimage.cfg.template hacking
- 实验8 LCD8*8点阵
- 解决Mysql中文乱码问题的方案
- create sequence
- 深入理解JVM一垃圾回收算法
- Delphi 中的自动释放策略