POJ - 1088 滑雪 dp
http://bailian.openjudge.cn/practice/1088?lang=en_US
题解:
设一个dp[N][N]数组代表从(i,j)坐标开始能滑到的最远距离。
更新的方法为 遍历每个dp[i][j], 对其四周(下一个状态)的点更新。
更新顺序为从低到高。所以用priority_queue存数据。 坑:
一开始更新的时候没有写dp=max(dp,····)
也忘记了答案是dp数组的最大值
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<cstring>
#include<set>
#include<algorithm>
#include<stack>
#include<string>
#include<cstdio>
#include<list>
#include<cstdlib>
#include<queue> #define _for(i, a, b) for (int i = (a); i<(b); ++i)
using namespace std;
const int N = + ;
const int INF = 1e6;
int map[N][N];
int dp[N][N];//从i,j开始能滑到的最远距离。dp[i][j] 对其四周的点更新。更新顺序为从高到底。
struct node {
int x, y, w;
node(int x = , int y = , int w = ) :x(x), y(y), w(w) {}
bool operator< (const node &b)const {
return w > b.w;
}
};
int dir[][] = { ,, ,-, -,, , };
priority_queue<node> Q;
int main() {
int c, r;
cin >> r >> c;
_for(i, , r)
_for(j, , c) {
cin >> map[i][j];
Q.push(node(i, j, map[i][j]));
dp[i][j] = ;
}
int ans = ; while (!Q.empty()) {
node now = Q.top(); ans = max(ans, dp[now.x][now.y]); Q.pop();
for (int i = ; i < ; i++) {
int dx = now.x + dir[i][];
int dy = now.y + dir[i][];
if (dx< || dx >= r || dy< || dy >= c)continue;
if (map[dx][dy] > now.w) dp[dx][dy] = max(dp[dx][dy], dp[now.x][now.y] + ); }
}
cout << ans;
//while (!Q.empty()) {cout << Q.top().w;Q.pop();}
system("pause");
}
POJ - 1088 滑雪 dp的更多相关文章
- poj 1088 滑雪 DP(dfs的记忆化搜索)
题目地址:http://poj.org/problem?id=1088 题目大意:给你一个m*n的矩阵 如果其中一个点高于另一个点 那么就可以从高点向下滑 直到没有可以下滑的时候 就得到一条下滑路径 ...
- POJ 1088 滑雪(记忆化搜索+dp)
POJ 1088 滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 107319 Accepted: 40893 De ...
- POJ 1088 滑雪(记忆化搜索)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 92384 Accepted: 34948 Description ...
- POJ 1088 滑雪 【记忆化搜索经典】
题目链接:http://poj.org/problem?id=1088 滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: ...
- poj 1088 滑雪(区间dp+记忆化搜索)
题目链接:http://poj.org/problem?id=1088 思路分析: 1>状态定义:状态dp[i][j]表示在位置map[i][j]可以滑雪的最长区域长度: 2>状态转移方程 ...
- POJ 1088 滑雪 记忆化DP
滑雪 Time Limit: 1000MS Memory Limit: 65536K Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度 ...
- POJ 1088: 滑雪(经典 DP+记忆化搜索)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 74996 Accepted: 27818 Description ...
- POJ 1088 滑雪(简单的记忆化dp)
题目 又一道可以称之为dp的题目,虽然看了别人的代码,但是我的代码写的还是很挫,,,,,, //看了题解做的简单的记忆化dp #include<stdio.h> #include<a ...
- POJ 1088 滑雪 -- 动态规划
题目地址:http://poj.org/problem?id=1088 Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当 ...
随机推荐
- Linux常用命令总结--基础命令
系统信息 1.arch 显示机器的处理器架构(1) 2.uname -m 显示机器的处理器架构(2) 3.lsb_release -a 查看操作系统版本 4.top 查看进程 5.free -m 查看 ...
- Greenplum-cc-web安装
第一章 文档概述 1. 本安装手册描述适用于Greenplum4.0以上版本的安装Greenplum-cc-web操作 第二章 安装介质 针对Greenplum版本下载对应Greenplum-cc-w ...
- windows本地hash值获取和破解详解
powershell版的procdump https://www.t00ls.net/articles-48428.html procdump procdump是微软官方提供的一个小工具, 微软官方下 ...
- mybatis 之 resultType="HashMap" parameterType="list"
public ServiceMessage<List<Map<String, Object>>> queryGoodsStockInfo(List<Long& ...
- MPAndroidChart market右边显示不全问题
//lineChart.setMarkerView(new CustomChartMarkerView(activity, R.layout.line_chart_maker));//add mark ...
- 剑指offer面试题5:逆序打印单链表(Java)
Java创建单链表(头插法.尾插法),并逆序打印单链表: package day_0324; import java.util.Scanner; import java.util.Stack; cla ...
- iOS - 转场时 appear 与 disappear 的调用顺序探索
不同的转场方式 A.B viewDidDisappear调用的流程不同 在A页面跳转到B页面的过程中 A 的 viewDidDisappear 方法和 B 的 viewDidAppear 谁先调用? ...
- React Native 开发工具篇
正文 概述:开发RN的工具有很多,选择性也比较多,比如Facebook专门为React开发的IDE:Nuclide,还有做前端比较熟悉的WebStorm.Sublime Text 3.VS Code等 ...
- hive报错: Specified key was too long; max key length is 767 bytes
废话不多说,报错如下: DataNucleus.Datastore (Log4JLogger.java:error(115)) - An exception was thrown while addi ...
- x64枚举DPC定时器
@写在前面 不同于x86,x64的DPC是被加密了的.对于x64DPC的兴趣始于我已经流产的scalpel计划.当时问某牛怎么遍历,得到的答案是“500大洋给代码”.真是R了狗了,好歹小哥我 ...