poj1088
这题是dp还是dfs+记忆化?(其实好像没什么区别?)
用f[i,j]表示滑到(i,j)时之后最多能滑多远,依次穷举每一个起点(i,j)则
f[i,j]=max{f[i,j-1],f[i-1,j],f[i+1,j],f[i,j+1]}+1 (当然滑到那个点的高度要小于(i,j)的高度)
const dx:array[..] of integer=(,,-,);
dy:array[..] of integer=(-,,,);
var f,a:array[..,..] of longint;
n,i,j,m,ans:longint;
function max(a,b:longint):longint;
begin
if a>b then max:=a else max:=b;
end;
procedure search(x,y:longint);
var i,xx,yy:integer;
maxx:longint;
begin
maxx:=;
for i:= to do
begin
xx:=x+dx[i];
yy:=y+dy[i];
if (a[xx,yy]<a[x,y]) and (f[xx,yy]=) then search(xx,yy);
if (a[xx,yy]<a[x,y]) then maxx:=max(maxx,f[xx,yy]);
end;
f[x,y]:=maxx+;
end; begin
readln(n,m);
for i:= to n+ do
for j:= to m+ do
a[i,j]:=;
for i:= to n do
begin
for j:= to m do
read(a[i,j]);
readln;
end;
for i:= to n do
for j:= to m do
if f[i,j]= then search(i,j);
for i:= to n do
for j:= to m do
ans:=max(ans,f[i,j]);
writeln(ans);
end.
poj1088的更多相关文章
- 【poj1088】 滑雪
http://poj.org/problem?id=1088 (题目链接) 题意 给出一个矩阵,任意选择一个起点,每次只能向周围4个格子中的值比当前格子小的格子移动,求最多能移动多少步. Soluti ...
- POJ1088(dp)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 91574 Accepted: 34573 Description ...
- DP----入门的一些题目(POJ1088 POJ1163 POJ1050)
动态规划入门 DP 基本思想 具体实现 经典题目 POJ1088 POJ1163 POJ1050 (一) POJ1088,动态规划的入门级题目.嘿嘿,连题目描述都是难得一见的中文. 题目分析: 求最长 ...
- dp例题02. 滑雪问题 (poj1088)
poj1088滑雪问题 题目链接:http://poj.org/status Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得 ...
- NUC_HomeWork1 -- POJ1088(DP)
D - 滑雪 Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Mic ...
- 北大poj-1088
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 88484 Accepted: 33177 Description ...
- POJ1088 滑雪
Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...
- POJ1088滑雪(dp+记忆化搜索)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 86411 Accepted: 32318 Description ...
- POJ1088滑雪(记忆化搜索+DFS||经典的动态规划)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 84297 Accepted: 31558 Description M ...
- POJ1088滑雪
Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...
随机推荐
- DevExpress控件使用系列--ASPxGridView+Popup+Tab
1.控件功能 列表控件展示数据.弹框控件执行编辑操作.Tab控件实现多标签编辑操官方说明 2.官方示例 2.1 ASPxGridView http ...
- html——a标签添加点击事件,火狐浏览器直接显示0
一.问题描述 给一个a标签添加了点击事件,页面直接给了0如下图 二.问题解决 后台调试模式下,发现也进了后台方法,也返回了页面. 于是想到先把页面里大部分内容去掉,去掉所有js,查看是否是部分代码有问 ...
- 获取c++ edit控件内容
CString str1,str2; ((CEdit*)GetDlgItem(IDC_EDIT1))->GetWindowText(str1); ((CEdit*)GetDlgItem(IDC_ ...
- hlsl 和cg 涉及 mul 左乘 右乘
error: 1. mul' implicit truncation of vector type 2. matrixXXX: array dimensions of(unknown scope en ...
- CentOS下使用cmake编译安装mysql
一.下载安装所必需的依赖包 1.因为高版本mysql都用cmake安装,所以下载cmake wget http://www.cmake.org/files/v3.0/cmake-3.0.1.tar.g ...
- SOAP vs REST
Both methods are used by many of the large players. It's a matter of preference. My preference is RE ...
- [转载]Spring Java Based Configuration
@Configuration & @Bean Annotations Annotating a class with the @Configuration indicates that the ...
- Linked List vs Array
Both Arrays and Linked List can be used to store linear data of similar types, but they both have so ...
- JsRender系列demo-10
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery.j ...
- IOS 中的MVC设计模式