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喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当 ...
随机推荐
- InsertSql
declare @hobby table(hobbyID int,hName nvarchar(100));insert into @hobby(hobbyID,hName)Select 1,'爬山' ...
- (转)base64编码是怎么工作的?
按:在PHP中级班的课堂上,有位同学问这样一个问题:“我在用 base64_encode 对用户名进行编码时,会出来等号,是不是可以去掉?”跟我来看完这篇文章,答案即揭晓. 1: 为什么需要base6 ...
- 虚拟机中多个Linux系统之间配置免秘钥访问
1.三个节点cdh1,cdh2,cdh3 2.在每个机器上分别生产公钥对 ssh-keygen -t rsa 3.复制公钥 cd .ssh cat id_rsa.pub >> auth ...
- javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }
一: 在app的build中android { ... defaultConfig { ... //添加如下配置就OK了 javaCompileO ...
- 【LeetCode OJ】Swap Nodes in Pairs
题目:Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2 ...
- WP8.1学习系列(第九章)——透视Pivot开发指南
Windows Phone 8 的 Pivot 控件 2014/6/18 适用于:Windows Phone 8 和 Windows Phone Silverlight 8.1 | Windows P ...
- WP8.1学习系列(第四章)——交互UX之导航模式
交互模式和指南 这部分包括三部分内容,分别是导航模式.命令模式和输入模式. 导航模式 虽然 Windows 导航模式提供了框架,但它提倡创新.激发你的创造力并在已建立的模式上构建. 命令模式 使用应用 ...
- 决策树归纳算法之ID3
学习是一个循序渐进的过程,我们首先来认识一下,什么是决策树.顾名思义,决策树就是拿来对一个事物做决策,作判断.那如何判断呢?凭什么判断呢?都是值得我们去思考的问题. 请看以下两个简单例子: 第一个例子 ...
- delphi for android 获取手机号
delphi for android 获取手机号 uses System.SysUtils, System.Types, System.UITypes, System.Classes, Syste ...
- Esper学习之三:进程模型
之前对Esper所能处理的事件结构进行了概述,并结合了例子进行讲解,不清楚的同学请看Esper学习之二:事件类型.今天主要为大家解释一下Esper是怎么处理事件的,即Esper的进程模型. 1.Upd ...