题意:在一个R*C(R, C<=100)的整数矩阵上找一条高度严格递减的最长路。起点任意,但每次只能沿着上下左右4个方向之一走一格,并且不能走出矩阵外。矩阵中的数均为0~100。

分析:dp[x][y]为从位置(x,y)出发的最长路。

#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 100 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int dp[MAXN][MAXN];
int pic[MAXN][MAXN];
int r, c;
bool judge(int x, int y){
return x >= 0 && x < r && y >= 0 && y < c;
}
int dfs(int x, int y){
if(dp[x][y] != -1) return dp[x][y];
int ans = 0;
for(int i = 0; i < 4; ++i){
int tmpx = x + dr[i];
int tmpy = y + dc[i];
if(judge(tmpx, tmpy) && pic[tmpx][tmpy] < pic[x][y]){
ans = Max(ans, dfs(tmpx, tmpy));
}
}
return dp[x][y] = ans + 1;
}
int main(){
int T;
scanf("%d", &T);
while(T--){
string name;
cin >> name;
scanf("%d%d", &r, &c);
for(int i = 0; i < r; ++i){
for(int j = 0; j < c; ++j){
scanf("%d", &pic[i][j]);
}
}
memset(dp, -1, sizeof dp);
int ans = 0;
for(int i = 0; i < r; ++i){
for(int j = 0; j < c; ++j){
ans = Max(ans, dfs(i, j));
}
}
printf("%s: %d\n", name.c_str(), ans);
}
return 0;
}

  

UVA - 10285 Longest Run on a Snowboard(最长的滑雪路径)(dp---记忆化搜索)的更多相关文章

  1. UVA 10285 - Longest Run on a Snowboard (记忆化搜索+dp)

    Longest Run on a Snowboard Input: standard input Output: standard output Time Limit: 5 seconds Memor ...

  2. UVA 10285 Longest Run on a Snowboard(记忆化搜索)

    Problem C Longest Run on a Snowboard Input: standard input Output: standard output Time Limit: 5 sec ...

  3. UVa 10285 Longest Run on a Snowboard - 记忆化搜索

    记忆化搜索,完事... Code /** * UVa * Problem#10285 * Accepted * Time:0ms */ #include<iostream> #includ ...

  4. UVa 10285 Longest Run on a Snowboard【记忆化搜索】

    题意:和最长滑雪路径一样, #include<iostream> #include<cstdio> #include<cstring> #include <c ...

  5. UVa 10285 - Longest Run on a Snowboard

    称号:给你一个二维矩阵,找到一个点.每一个可以移动到的位置相邻的上下,求最长单调路径. 分析:贪婪,dp.搜索. 这个问题是一个小样本,我们该怎么办. 这里使用贪心算法: 首先.将全部点依照权值排序( ...

  6. UVA - 10285 Longest Run on a Snowboard (线性DP)

    思路:d[x][y]表示以(x, y)作为起点能得到的最长递减序列,转移方程d[x][y] = max(d[px][py] + 1),此处(px, py)是它的相邻位置并且该位置的值小于(x, y)处 ...

  7. 状压DP+记忆化搜索 UVA 1252 Twenty Questions

    题目传送门 /* 题意:给出一系列的01字符串,问最少要问几个问题(列)能把它们区分出来 状态DP+记忆化搜索:dp[s1][s2]表示问题集合为s1.答案对错集合为s2时,还要问几次才能区分出来 若 ...

  8. UVA 10003 Cutting Sticks 区间DP+记忆化搜索

    UVA 10003 Cutting Sticks+区间DP 纵有疾风起 题目大意 有一个长为L的木棍,木棍中间有n个切点.每次切割的费用为当前木棍的长度.求切割木棍的最小费用 输入输出 第一行是木棍的 ...

  9. UVa 10599【lis dp,记忆化搜索】

    UVa 10599 题意: 给出r*c的网格,其中有些格子里面有垃圾,机器人从左上角移动到右下角,只能向右或向下移动.问机器人能清扫最多多少个含有垃圾的格子,有多少中方案,输出其中一种方案的格子编号. ...

随机推荐

  1. S7-300过程映像区详解

      一.概念  W过程镜像区输入字 PIW立即输入区字  PIW不用等系统刷新,立即读入 IW等待系统刷新后读入   二.PIW/IW,PQW/QW  引用西门子论坛一位大侠的比方加深理解:      ...

  2. HTML学习第五天

    HTML学习第五天 今天学HTML的实体.背景.布局 HTML布局的标签基本被淘汰frameset就被淘汰了,只有iframe依然存活,但是iframe可以被CSS给代替.下面就是一个练习的程序 &l ...

  3. python merge、join、concat用法与区别

     由于合并变化较大,以后函数可能会修改,只给出一些例子作为参考 总结: merge.join 1.当没有索引时:merge.join为按照一定条件合并 2.当有索引.并按照索引合并时,得到结果为两者混 ...

  4. CSS - flex使行内元素快速对齐

    div{ display:flex; alian-items:center; //使垂直对齐 justify-content:center //使水平对齐 }

  5. ubuntu14安装一些常用的软件

    1.搜狗输入法: 2.sublime 3. 搜狗输入法在Linux里面还是很正常的,并没有想在windows下那样充斥这各种广告. 在搜狗的官网下载了输入法-->双击安装-->提示存在依赖 ...

  6. centos6或7查看端口占用及解除占用

    一.查看端口占用 netstat -lnp|grep 要查看的端口号 例如:查看占用端口7000的进程 netstat -lnp|grep 7000 二.清除占用 (1)一次性的清除占用80端口的程序 ...

  7. 吴裕雄--天生自然java开发常用类库学习笔记:Map接口

    import java.util.HashMap ; import java.util.Map ; public class HashMapDemo01{ public static void mai ...

  8. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):带有字体图标的导航栏

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  9. Ubuntu1804 双网卡的设置

    在WIFI模式下,既可以使用ping开发板,又可上网.     目标:ubuntu1804下使用两个网卡 网卡(eth0):用于桥接主机的物理网卡 网卡(eth1):用于NAT模式下共享主机IP,用于 ...

  10. MongoDB_02简介

    MongoDB简介 MongoDB是一个开源,高性能,无模式的文档型数据库. 它支持的数据结构非常松散,是一种类似于JSON的格式叫BSON,所以他既可以存储比较复杂的数据类型,又相当的灵活. Mon ...