【poj1088】 滑雪
http://poj.org/problem?id=1088 (题目链接)
题意
给出一个矩阵,任意选择一个起点,每次只能向周围4个格子中的值比当前格子小的格子移动,求最多能移动多少步。
Solution
其实很简单,将矩阵中的值进行排序,从小到大更新。比如说当前点(i,j),它只能由周围4个点走到,所以取最大值,而排序就保证了更新的顺序不会出错。
代码
- // poj1088
- #include<algorithm>
- #include<iostream>
- #include<cstdlib>
- #include<cstring>
- #include<cstdio>
- #include<cmath>
- #define LL long long
- #define inf 2147483640
- #define Pi 3.1415926535898
- #define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
- using namespace std;
- struct data {int w,r,c;}a[1000010];
- int f[1010][1010],r,c,cnt,h[1010][1010];
- bool cmp(data a,data b) {return a.w<b.w;}
- int main() {
- scanf("%d%d",&r,&c);
- memset(h,0x7f,sizeof(h));
- for (int i=1;i<=r;i++)
- for (int j=1;j<=c;j++) {
- int w;
- scanf("%d",&w);h[i][j]=w;
- a[++cnt].w=w;a[cnt].r=i;a[cnt].c=j;
- }
- sort(a+1,a+1+cnt,cmp);
- int ans=0;
- for (int i=1;i<=cnt;i++) {
- int x=a[i].r,y=a[i].c,w=a[i].w;
- if (w>h[x-1][y]) f[x][y]=max(f[x][y],f[x-1][y]+1);
- if (w>h[x][y-1]) f[x][y]=max(f[x][y],f[x][y-1]+1);
- if (w>h[x+1][y]) f[x][y]=max(f[x][y],f[x+1][y]+1);
- if (w>h[x][y+1]) f[x][y]=max(f[x][y],f[x][y+1]+1);
- }
- for (int i=1;i<=r;i++)
- for (int j=1;j<=c;j++) ans=max(ans,f[i][j]);
- printf("%d",ans+1);
- return 0;
- }
【poj1088】 滑雪的更多相关文章
- POJ1088 滑雪
Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...
- POJ1088滑雪(dp+记忆化搜索)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 86411 Accepted: 32318 Description ...
- POJ1088滑雪(记忆化搜索+DFS||经典的动态规划)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 84297 Accepted: 31558 Description M ...
- POJ1088滑雪
Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...
- [POJ1088] 滑雪(递归dp)
Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...
- POJ-1088 滑雪 (记忆化搜索,dp)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 86318 Accepted: 32289 Description Mich ...
- poj1088 滑雪 解题报告
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 77423 Accepted: 28779 Description ...
- ACM学习历程—POJ1088 滑雪(dp && 记忆化搜索)
Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...
- poj1088滑雪最短路径
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 97281 Accepted: 36886 Description ...
- 经典DP问题--poj1088滑雪
Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...
随机推荐
- android ant 自动编译打包
http://www.cnblogs.com/tankaixiong/archive/2010/11/24/1887156.html
- Lambda表达式关于like问题(未解决)
参考文章: http://stackoverflow.com/questions/3616215/like-in-lambda-expression-and-linq 1. c=>c.name. ...
- Socket Programming in C#--Conclusion
Conclusion And that's all there is to it! Here is how our client looks like Here is how our server l ...
- 【Andorid------手势识别】GestureDetector和SimpleOnGestureListener的使用教程(转)——
FROM:http://www.cnblogs.com/transmuse/archive/2010/12/02/1894833.html 1. 当用户触摸屏幕的时候,会产生许多手势,例如down,u ...
- C语言 三级指针的应用
//三级指针的使用 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #includ ...
- oracle系统包—-dbms_output用法
dbms_output包主要用于调试pl/sql程序,或者在sql*plus命令中显示信息(displaying message)和报表,譬如我们可以写一个简单的匿名pl/sql程序块,而该块出于某种 ...
- 一款Android开源的下拉刷新动画
无意间在GitHub看到的,就Down了下来.但是作者是用AndroidStudio开发的,这边移动Eclipse供小伙伴们下载使用. 截图 这么好的东西因为字数不够不让分享,得了,贴段代码吧 pac ...
- WindowsService(Windows服务)开发步骤附Demo
1.打开VS,新建项目,选择Windows服务,然后设置目录及项目名称后点击确定. 2.展开Service1服务文件,编写service1.cs类文件,不是Service1[设计].然后修改OnSta ...
- [MetaHook] Quake OpenGL function
Quake OpenGL function for MetaHook plugin. Thank hzqst :D QGL.h #ifndef QGL_H #define QGL_H #include ...
- Quartz.NET syudy
Quartz.NET Quartz.NET是一个开源的作业调度框架,是OpenSymphony 的 Quartz API的.NET移植,它用C#写成,可用于winform和asp.net应用中.它 ...