1、http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1226

2、题目大意:

给定一个二维的矩阵,其中的数分别代表一些高度,现在可以从某一点滑雪,只能从高处往低处滑,问一条路径最多可以经过多少个点

3、题目:

Problem C

Longest Run on a Snowboard

Input: standard input

Output: standard output

Time Limit: 5 seconds

Memory Limit: 32 MB

Michael likes snowboarding. That's not very surprising, since snowboarding is really great. The bad thing is that in order to gain speed, the area must slide downwards. Another disadvantage is that when you've reached the bottom of the hill you have to walk up again or wait for the ski-lift.

Michael would like to know how long the longest run in an area is. That area is given by a grid of numbers, defining the heights at those points. Look at this example:

 1  2  3  4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9

One can slide down from one point to a connected other one if and only if the height decreases. One point is connected to another if it's at left, at right, above or below it. In the sample map, a possible slide would be 24-17-16-1 (start at 24, end at 1). Of course if you would go 25-24-23-...-3-2-1, it would be a much longer run. In fact, it's the longest possible.

Input

The first line contains the number of test cases N. Each test case starts with a line containing the name (it's a single string), the number of rows Rand the number of columns C. After that follow R lines with C numbers each, defining the heights. R and C won't be bigger than 100N not bigger than 15 and the heights are always in the range from 0 to 100.

For each test case, print a line containing the name of the area, a colon, a space and the length of the longest run one can slide down in that area.

Sample Input
2
Feldberg 10 5
56 14 51 58 88
26 94 24 39 41
24 16 8 51 51
76 72 77 43 10
38 50 59 84 81
5 23 37 71 77
96 10 93 53 82
94 15 96 69 9
74 0 62 38 96
37 54 55 82 38
Spiral 5 5
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9

Sample Output

Feldberg: 7
Spiral: 25

(Math Lovers’ Contest, Problem Setter: Stefan Pochmann)

4、代码:

#include<stdio.h>
#include<string.h>
#define N 105
#include<algorithm>
using namespace std;
int a[N][N];
int dp[N][N];
int dir[4][2]={-1,0,1,0,0,-1,0,1};
int m,n;
int dfs(int x,int y)
{int tmp=0;if(dp[x][y])return dp[x][y];for(int i=0;i<4;i++){int tx=x+dir[i][0];int ty=y+dir[i][1];if(tx>=1 && tx<=m && ty>=1 && ty<=n && a[tx][ty]<a[x][y]){tmp=max(tmp,dfs(tx,ty));}}dp[x][y]=tmp+1;return dp[x][y];
}
int main()
{int t;char str[105];scanf("%d",&t);while(t--){int ans=0;scanf("%s%d%d",str,&m,&n);for(int i=1;i<=m;i++){for(int j=1;j<=n;j++)scanf("%d",&a[i][j]);}memset(dp,0,sizeof(dp));for(int i=1;i<=m;i++){for(int j=1;j<=n;j++){if(dp[i][j])//如果计算过了ans=max(ans,dp[i][j]);elseans=max(ans,dfs(i,j));}}printf("%s: %d\n",str,ans);}return 0;
}

uva 10285 - Longest Run on a Snowboard(dp+记忆化搜索)相关推荐

  1. uva 10285——Longest Run on a Snowboard

    题意:在一个R*c的矩阵上找一条高度严格递减的最长路,起点任意,每次可以走上下左右. 思路:DAG上的最长路问题,直接套用记忆化搜索的模板,dp(i,j)=max(dp(ii,jj)四个方向最大值), ...

  2. UVA 1220 Party at Hali-Bula (树状DP+记忆化搜索)

    Dear Contestant, I'm going to have a party at my villa at Hali-Bula to celebrate my retirement from ...

  3. UVA - 11361 Investigating Div-Sum Property(数位dp/记忆化搜索板子)

    题目:https://vjudge.net/problem/UVA-11361 思路:数位dp,用记忆化搜索写,dp[pos][i][j][limit] 代表剩余有pos位,每位上的数字和模k 等于i ...

  4. 思维dp ---- Codeforces Round #711 (Div. 2) - C. Planar Reflections[dp/记忆化搜索]

    题目链接 题目大意: 就是给你n个平面和一个寿命为k的衰变粒子.开始粒子从左向右飞行,粒子每经过一个平面就会产生一个副本粒子,这个副本粒子比原粒子的寿命少1,即为k-1,并且飞行方向是原粒子的反方向. ...

  5. BZOJ1415 [Noi2005]聪聪和可可 【SPFA + 期望dp记忆化搜索】

    题目 输入格式 数据的第1行为两个整数N和E,以空格分隔,分别表示森林中的景点数和连接相邻景点的路的条数. 第2行包含两个整数C和M,以空格分隔,分别表示初始时聪聪和可可所在的景点的编号. 接下来E行 ...

  6. HDU 5001 概率DP || 记忆化搜索

    2014 ACM/ICPC Asia Regional Anshan Online 给N个点,M条边组成的图,每一步能够从一个点走到相邻任一点,概率同样,问D步后没走到过每一个点的概率 概率DP  測 ...

  7. 数位dp 记忆化搜索java_hdu 5787 数位dp,记忆化搜索

    题意:求区间[l,r]内有多少个数符合,这个数的任意的相邻k位数(digits),这k个数都两两不相等 l,r范围是1~1e18,k是2~5 思路:数位DP,因为K<=5,我们最多需要保存下来当 ...

  8. pku 1191 棋盘分割 DP / 记忆化搜索

    http://poj.org/problem?id=1191 题意:中文省略. 思路:黑说p116有讲解, 主要的状态转移方程为 横着切: dp[k][x1][y1][x2][y2]  = min(d ...

  9. bzoj1833: [ZJOI2010]count 数字计数(数位DP+记忆化搜索)

    1833: [ZJOI2010]count 数字计数 题目:传送门 题解: 今天是躲不开各种恶心DP了??? %爆靖大佬啊!!! 据说是数位DP裸题...emmm学吧学吧 感觉记忆化搜索特别强: 定义 ...

最新文章

  1. EntityFramework Core解决并发详解
  2. idea 2019安装完(打不开启动不了)问题解决(最全解决方法)
  3. lc171. Excel Sheet Column Number
  4. 25LINQ拾遗及实例
  5. php多个表中查找数据_Excel实战技巧74: 在工作表中创建搜索框来查找数据
  6. 岗岭集团打造中国最大的线上线下一体化的医药健康平台
  7. C++ 常量类型 const 详解
  8. MVVM模式下 触发器多条件判断
  9. L1-041 寻找250 (10 分)—团体程序设计天梯赛
  10. 深度学习之GAN对抗神经网络
  11. 2022计算机三级数据库总结和经验(有免费题库)
  12. 软件测试的简历里面,项目介绍要怎么写好呢
  13. 三维空间的位姿描述和齐次变换
  14. HTML5实习手机端浏览器拍照和本地上传
  15. joomla新建模板_WordPress v Joomla:模板和主题
  16. 安徽大学计算机学院张静,安徽大学2011年国家励志奖学金获奖学生名单
  17. 【经验总结】小白挖洞十天经验分享
  18. Verilog语言控制Xilinx FPGA引脚demo
  19. APP下载链接在微信内打不开显示已停止访问该网页怎么办?
  20. 如何在win7 64下安装ipython notebook

热门文章

  1. Ballerina语言有望改善应用程序集成
  2. php发送邮件——SMTP服务器配置图文教程
  3. 2021年全球天然橡胶行业供需现状分析:需求量迎来恢复性增长,中国市场需求量占比超40%[图]
  4. 【缓存】@CacheEvict
  5. <Halcon>基于形状和轮廓的模板匹配
  6. Unity Shader学习记录(6) —— 高光反射光照模型和内置计算函数
  7. 史上最简单MySQL教程详解(进阶篇)之视图
  8. 什么是操作系统(OS)?都有哪些常见的分类?
  9. WORD文档无法编辑解决
  10. 求函数:x的n次方(函数递归)