poj 1088(DP+递归)
这题状态方程很容易得到:DP[i][j] = max(DP[i-1][j],DP[i+1][j],DP[i][j-1],DP[i][j+1]) + 1
难点在于边界条件和剪枝,因为这方程的条件是点在map里,且只有递增关系才会变化,如果用循环的话要判断递增,所以用递归比较方便
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <stack>
using namespace std; #define mem(a,b) memset(a,b,sizeof(a))
#define pf printf
#define sf scanf
#define debug printf("!\n")
#define INF 10000
#define MAX(a,b) a>b?a:b
#define blank pf("\n")
#define LL long long int n,m,V;
int dp[][],map[][]; int f(int i,int j)
{
if(dp[i][j]!=)
return dp[i][j];
int w,s,a,d;
if(i->=)
{
if(map[i-][j]<map[i][j]) s=f(i-,j)+;
else s=;
}
else s=;
if(i+<=n)
{
if(map[i+][j]<map[i][j]) w=f(i+,j)+;
else w=;
}
else w=;
if(j->=)
{
if(map[i][j-]<map[i][j]) a=f(i,j-)+;
else a=;
}
else a=;
if(j+<=m)
{
if(map[i][j+]<map[i][j]) d=f(i,j+)+;
else d=;
}
else d=; int max1 = max(w,s);
int max2 = max(a,d);
return max(max1,max2); } int main()
{
int i,j,t;
while(~sf("%d%d",&n,&m))
{
mem(dp,);
dp[][] =;
for(i=;i<=n;i++)
{
for(j = ;j<=m;j++)
sf("%d",&map[i][j]);
}
int max = ;
for(i=;i<=n;i++)
{
for(j = ;j<=m;j++)
{
dp[i][j]=f(i,j);
if(max<dp[i][j]) max = dp[i][j];
}
}
pf("%d\n",max); }
}
poj 1088(DP+递归)的更多相关文章
- poj 1088 dp **
链接:点我 记忆化搜索很好写 #include<cstdio> #include<iostream> #include<algorithm> #include< ...
- POJ 1088 DP=记忆化搜索
话说DP=记忆化搜索这句话真不是虚的. 面对这道题目,题意很简单,但是DP的时候,方向分为四个,这个时候用递推就好难写了,你很难得到当前状态的前一个真实状态,这个时候记忆化搜索就派上用场啦! 通过对四 ...
- 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 滑雪(区间dp+记忆化搜索)
题目链接:http://poj.org/problem?id=1088 思路分析: 1>状态定义:状态dp[i][j]表示在位置map[i][j]可以滑雪的最长区域长度: 2>状态转移方程 ...
- poj 1088 滑雪 DP(dfs的记忆化搜索)
题目地址:http://poj.org/problem?id=1088 题目大意:给你一个m*n的矩阵 如果其中一个点高于另一个点 那么就可以从高点向下滑 直到没有可以下滑的时候 就得到一条下滑路径 ...
- POJ - 1088 滑雪 dp
http://bailian.openjudge.cn/practice/1088?lang=en_US 题解: 设一个dp[N][N]数组代表从(i,j)坐标开始能滑到的最远距离.更新的方法为 遍历 ...
- poj 1141 区间dp+递归打印路径
Brackets Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 30383 Accepted: 871 ...
- DP:Skiing(POJ 1088)
北大教你怎么滑雪 题目是中文的,要读懂题目其实不难 其实这道题挺经典的,我们这样想,他最终要找到一个最大值,这个时候我们就想到要用动态规划 那怎么用呢?我们同时这样想,由于滑雪的最高点我们不能立马找 ...
随机推荐
- 64位虚拟机中安装CentOS_6.7
虚拟机VirtualBox-4.3.24-98716-Win.1425444683.exe,操作系统选用CentOS-6.7-x86_64-LiveDVD .iso. 1) 启动VirtualBox, ...
- 根据现有PDF模板填充信息(SpringBoot)
根据现有PDF模板填充信息(SpringBoot+maven) 首先得有一个pdf模板,建立pdf模板需要下载工具 红色框为文本框,filename为域名.java需要根据域名赋值 pom 文件配置 ...
- GraphQL 如何取代 Redux
简评:使用 GraphQL 可以大大简化客户端状态管理部分的代码. ⚛️切换到React 故事背景:在 2016 年,Pathwright 的前端团队就开始将客户端的代码从 Backbone & ...
- Python小实验——读&写Excel文件内容
安装xlrd模块和xlwt模块 读取Excel文件了内容需要额外的模块-- \(xlrd\),在官网上可以找到下载:https://pypi.python.org/pypi/xlrd#download ...
- FlowPortal-BPM——创建新模块
一.设置webconfig (1)数据源设置 添加所有所用到数据库 (2)修改企业信息 二.Main.ashx——添加新的功能选项卡 new { id = "EXECUTE", t ...
- FTP在docker容器中上传失败解决,改为被动模式
package com.mayocase.takeout.utils; import org.apache.commons.net.ftp.FTPClient; import org.apache.c ...
- python bytes和str之间的转换
1 # bytes object 2 b = b"example" 3 4 # str object 5 s = "example" 6 7 # str to ...
- GoLand 调试 Go
Goland 调试 Go 从百度得知 VS Code 不能很好的支持 Go 的调试真让人肝儿疼 -- 引言 准备 Win 10 Pro Go(Version 1.10) GoLand(2018.3) ...
- PTA 这是二叉搜索树吗?
https://pintia.cn/problem-sets/994805046380707840/problems/994805070971912192 #include<iostream&g ...
- [转] js画图开发库--mxgraph--[graphlayout-图形布局.html]
[From] http://chwshuang.iteye.com/blog/1797740 布局变化,下方还有动画效果选项: <!Doctype html> <html xmlns ...