记忆化搜索,完事。。。

Code

 /**
* UVa
* Problem#10285
* Accepted
* Time:0ms
*/
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<ctime>
#include<map>
#include<stack>
#include<set>
#include<queue>
#include<vector>
#ifndef WIN32
#define AUTO "%lld"
#else
#define AUTO "%I64d"
#endif
using namespace std;
typedef bool boolean;
#define inf 0xfffffff
#define smin(a, b) (a) = min((a), (b))
#define smax(a, b) (a) = max((a), (b))
template<typename T>
inline boolean readInteger(T& u) {
char x;
int aFlag = ;
while(!isdigit((x = getchar())) && x != '-' && x != -);
if(x == -) {
ungetc(x, stdin);
return false;
}
if(x == '-') {
aFlag = -;
x = getchar();
}
for(u = x - ''; isdigit((x = getchar())); u = u * + x - '');
u *= aFlag;
ungetc(x, stdin);
return true;
} template<typename T>class Matrix{
public:
T *p;
int lines;
int rows;
Matrix():p(NULL){ }
Matrix(int rows, int lines):lines(lines), rows(rows){
p = new T[(lines * rows)];
}
T* operator [](int pos){
return (p + pos * lines);
}
};
#define matset(m, i, s) memset((m).p, (i), (s) * (m).lines * (m).rows) int T;
char name[];
int n, m;
Matrix<int> h; inline void init() {
scanf("%s", name);
readInteger(n);
readInteger(m);
h = Matrix<int>(n, m);
for(int i = ; i < n; i++) {
for(int j = ; j < m; j++) {
readInteger(h[i][j]);
}
}
} const int mov[][] = {{, , , -}, {, , -, }};
boolean isExceeded(int x, int y) {
if(x < || x >= n) return true;
if(y < || y >= m) return true;
return false;
} Matrix<int> f;
int dfs(int x, int y) {
if(f[x][y]) return f[x][y];
for(int i = , ret; i < ; i++) {
int x0 = x + mov[][i], y0 = y + mov[][i];
if(isExceeded(x0, y0)) continue;
if(h[x0][y0] >= h[x][y]) continue;
ret = dfs(x0, y0);
smax(f[x][y], ret + );
}
if(f[x][y] == ) f[x][y] = ;
return f[x][y];
} inline void solve() {
f = Matrix<int>(n, m);
matset(f, , sizeof(int));
int res = ;
for(int i = ; i < n; i++) {
for(int j = ; j < m; j++) {
if(f[i][j] == )
dfs(i, j);
smax(res, f[i][j]);
}
}
printf("%s: %d\n", name, res);
delete[] f.p;
delete[] h.p;
} int main() {
readInteger(T);
while(T--) {
init();
solve();
}
return ;
}

UVa 10285 Longest Run on a Snowboard - 记忆化搜索的更多相关文章

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

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

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

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

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

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

  4. UVa 10285 - Longest Run on a Snowboard

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

  5. 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)处 ...

  6. UVA - 10285 Longest Run on a Snowboard(最长的滑雪路径)(dp---记忆化搜索)

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

  7. UVA 825 Walking on the Safe Side(记忆化搜索)

      Walking on the Safe Side  Square City is a very easy place for people to walk around. The two-way ...

  8. uva 10581 - Partitioning for fun and profit(记忆化搜索+数论)

    题目链接:uva 10581 - Partitioning for fun and profit 题目大意:给定m,n,k,将m分解成n份,然后依照每份的个数排定字典序,而且划分时要求ai−1≤ai, ...

  9. 【UVA 437】The Tower of Babylon(记忆化搜索写法)

    [题目链接]:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

随机推荐

  1. 不移除通知的话,出现的bug

    没销毁的私聊控制器仍然监听到了通知,发送表情

  2. 洛谷P3243 [HNOI2015]菜肴制作 拓扑排序+贪心

    正解:拓扑排序 解题报告: 传送门! 首先看到它这个约束就应该要想到拓扑排序辣QwQ 首先想到的应该是用优先队列代替队列,按照节点编号排序 然后也很容易被hack:<5,1> 正解应为5, ...

  3. Java GUI程序设计

    在实际应用中,我们见到的许多应用界面都属于GUI图形型用户界面.如:我们点击QQ图标,就会弹出一个QQ登陆界面的对话框.这个QQ图标就可以被称作图形化的用户界面. 其实,用户界面的类型分为两类:Com ...

  4. 10 ref 和 out 之间的差别

    (1) 两者都是按地址传递的,使用后都将改变原来的数值 (2) ref传进去的參数必须在调用前初始化,out不必 (3) ref传进去的參数在函数内部能够直接使用,而out不可 (4) ref传进去的 ...

  5. Jedis 对 Redis 的操作详解

    1. JedisUtil2. 键操作3. 字符串操作4. 字节串4. 整数和浮点数5. 列表6. 集合(Set)7. 散列8. 排序sort 本篇主要阐述Jedis对redis的五大类型的操作:字符串 ...

  6. 开源的挖矿软件,sha256

    http://cryptomining-blog.com/tag/sha-256d-miner/ https://github.com/cbuchner1/CudaMiner/blob/master/ ...

  7. word自动导入目录

    1:如果在编写word时,有给各章添加标题,可以使用word的目录生成功能,如图:

  8. Tomcat重启session失效

    在Tomcat的目录下找到context.xml,取消掉<Manager pathname="" /> 这句的注释.

  9. libsvm使用

    先挖个坑,有空重写svm_scale, svm_train, svm_predict几个代码,给的实在写的不敢恭维 package org.ml.svm; import java.io.File; i ...

  10. selenium-python:登录网站并签到

    测试网站的图像验证码统一设置成了:121 Elements中定位元素比较费眼睛~~ import time from selenium import webdriver # import os use ...