Codevs 2152 滑雪 记忆化搜索DP
来源:互联网 发布:js div添加class 编辑:程序博客网 时间:2024/05/29 11:20
Codevs 2152 滑雪
dp[i][j] 为从 i, j 开始走能走多长距离。
代码
#include <iostream>#include <cstdio>#include <queue>#include <cstring>using namespace std;#define MAXN (100+10)const int dx[] = {0,1,0,-1,0};const int dy[] = {0,0,1,0,-1};int n, m;int maps[MAXN][MAXN];int dp[MAXN][MAXN];int dfs(int x, int y){ if(dp[x][y]) return dp[x][y]; int ans = 1; for(int i = 1; i <= 4; i ++) { int nx = x + dx[i]; int ny = y + dy[i]; if(nx >= 1 && nx <= n && ny >= 1 && ny <= m && maps[nx][ny] < maps[x][y]) ans = max(ans, dfs(nx, ny)+1); } dp[x][y] = ans; return ans;}int main(){ cin >> n >> m; for(int i = 1; i <= n; i ++) for(int j = 1; j <= m; j ++) scanf("%d", &maps[i][j]); for(int i = 1; i <= n; i ++) for(int j = 1; j <= m; j ++) dfs(i,j); int ans = 0; for(int i = 1; i <= n; i ++) for(int j = 1; j <= m; j ++) ans = max(ans, dp[i][j]); cout << ans << endl; return 0;}
0 0
- Codevs 2152 滑雪 记忆化搜索DP
- 【codevs】2152 滑雪 记忆化搜索
- POJ 1088 滑雪(DP+记忆化搜索)
- 滑雪(poj1088,DP+记忆化搜索)
- POJ1088 滑雪 DP+记忆化搜索
- poj-1088-滑雪【记忆化搜索+DP】
- [OpenJudge-NOI]滑雪 记忆化搜索+Dp
- poj1088滑雪--dp之记忆化搜索
- POJ - 1088 滑雪 DP+记忆化搜索
- poj 1088滑雪(记忆化搜索, dp)
- 【记忆化搜索】滑雪(dp模板)
- 滑雪(dp 记忆化搜索)
- 【QAQ】codevs滑雪和记忆化搜索的小经验
- 滑雪 记忆化搜索
- 【记忆化搜索】滑雪
- 【记忆化搜索】滑雪
- 滑雪--记忆化搜索
- 滑雪【记忆化搜索】
- movword [LABEL_DESC_CODE32 + 2], ax
- HTC VIVE开发教程(五)
- android 代码混淆中ProGuard使用详情
- Jquery简单介绍
- BufferedReader和BufferedWriter
- Codevs 2152 滑雪 记忆化搜索DP
- GDI透明贴图
- ShowModalDialog常见的几个问题——表单提交、传值、反馈
- Redis系列~发布订阅(十一)
- Qt ini配置文件
- 升级php-5.6.19 和php-fpm5.6.19
- uva12170 Easy Climb
- 10_26
- [USACO09NOV]Job Hunt