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

记忆化搜索,完事。。。
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 - 记忆化搜索的更多相关文章
- UVA 10285 Longest Run on a Snowboard(记忆化搜索)
Problem C Longest Run on a Snowboard Input: standard input Output: standard output Time Limit: 5 sec ...
- UVA 10285 - Longest Run on a Snowboard (记忆化搜索+dp)
Longest Run on a Snowboard Input: standard input Output: standard output Time Limit: 5 seconds Memor ...
- UVa 10285 Longest Run on a Snowboard【记忆化搜索】
题意:和最长滑雪路径一样, #include<iostream> #include<cstdio> #include<cstring> #include <c ...
- UVa 10285 - Longest Run on a Snowboard
称号:给你一个二维矩阵,找到一个点.每一个可以移动到的位置相邻的上下,求最长单调路径. 分析:贪婪,dp.搜索. 这个问题是一个小样本,我们该怎么办. 这里使用贪心算法: 首先.将全部点依照权值排序( ...
- 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)处 ...
- UVA - 10285 Longest Run on a Snowboard(最长的滑雪路径)(dp---记忆化搜索)
题意:在一个R*C(R, C<=100)的整数矩阵上找一条高度严格递减的最长路.起点任意,但每次只能沿着上下左右4个方向之一走一格,并且不能走出矩阵外.矩阵中的数均为0~100. 分析:dp[x ...
- 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 ...
- uva 10581 - Partitioning for fun and profit(记忆化搜索+数论)
题目链接:uva 10581 - Partitioning for fun and profit 题目大意:给定m,n,k,将m分解成n份,然后依照每份的个数排定字典序,而且划分时要求ai−1≤ai, ...
- 【UVA 437】The Tower of Babylon(记忆化搜索写法)
[题目链接]:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
随机推荐
- Pragma: no-cache
PHP Advanced and Object-Oriented Programming Larry Ullman Last-Modified 最后修改时间 Expires 过期时间 Pragma ...
- iOS多线程编程之自定义NSOperation(转载)
一.实现一个简单的tableView显示效果 实现效果展示: 代码示例(使用以前在主控制器中进行业务处理的方式) 1.新建一个项目,让控制器继承自UITableViewController. 1 // ...
- 洛谷P4138 挂饰 背包
正解:背包dp 解题报告: 昂先放链接qwq 感觉还挺妙的,,,真的我觉得我直接做可能是想不到背包的,,,我大概想不出是个背包的QAQ 但是知道是背包之后觉得,哦,好像长得也确实挺背包的吼,而且其实是 ...
- struts2 OGNL(Object-Graph Navigation Language) 井号,星号,百分号
1.“#”主要有三种用途: 访问OGNL上下文和Action上下文,#相当于ActionContext.getContext():可以访问这几个ActionContext中的属性. parameter ...
- Java并发包中CyclicBarrier的源码分析和使用
CyclicBarrier的介绍和源码分析 CyclicBarrier的字母意思是可循环(Cyclic)使用的屏障(Barrier).它要做的事情是,让一组线程到达一个屏障(也可以叫做同步点)时被阻塞 ...
- [MySQL 5.6] MySQL 5.6 group commit 性能测试及内部实现流程
[MySQL 5.6] MySQL 5.6 group commit 性能测试及内部实现流程 http://mysqllover.com/?p=581 尽管Mariadb以及Facebook在long ...
- spring用注解简化bean配置
组件扫描: <context:component-scan base-package="com"/> 容器启动后如果发现配置文件有上面的标签会自动扫描对应的包及子包,如 ...
- python中的re模块中的向后引用和零宽断言
1.后向引用 pattern = re.compile(r"(\w+)")#['hello', 'go', 'go', 'hello'] # pattern = re.compil ...
- Leetcode: Binary Tree Inorder Transversal
Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tr ...
- IO—代码—基础及其用例
字节流:文件.图片.歌曲 使用字节流的应用场景:如果是读写的数据都不需要转换成字符的时候,则使用字节流. 字节流处理单元为1个字节, 操作字节和字节数组.不能直接处理Unicode字符 字节流可用于任 ...