http://poj.org/problem?id=1088 (题目链接)

题意

  给出一个矩阵,任意选择一个起点,每次只能向周围4个格子中的值比当前格子小的格子移动,求最多能移动多少步。

Solution

  其实很简单,将矩阵中的值进行排序,从小到大更新。比如说当前点(i,j),它只能由周围4个点走到,所以取最大值,而排序就保证了更新的顺序不会出错。

代码

  1. // poj1088
  2. #include<algorithm>
  3. #include<iostream>
  4. #include<cstdlib>
  5. #include<cstring>
  6. #include<cstdio>
  7. #include<cmath>
  8. #define LL long long
  9. #define inf 2147483640
  10. #define Pi 3.1415926535898
  11. #define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
  12. using namespace std;
  13.  
  14. struct data {int w,r,c;}a[1000010];
  15.  
  16. int f[1010][1010],r,c,cnt,h[1010][1010];
  17.  
  18. bool cmp(data a,data b) {return a.w<b.w;}
  19. int main() {
  20. scanf("%d%d",&r,&c);
  21. memset(h,0x7f,sizeof(h));
  22. for (int i=1;i<=r;i++)
  23. for (int j=1;j<=c;j++) {
  24. int w;
  25. scanf("%d",&w);h[i][j]=w;
  26. a[++cnt].w=w;a[cnt].r=i;a[cnt].c=j;
  27. }
  28. sort(a+1,a+1+cnt,cmp);
  29. int ans=0;
  30. for (int i=1;i<=cnt;i++) {
  31. int x=a[i].r,y=a[i].c,w=a[i].w;
  32. if (w>h[x-1][y]) f[x][y]=max(f[x][y],f[x-1][y]+1);
  33. if (w>h[x][y-1]) f[x][y]=max(f[x][y],f[x][y-1]+1);
  34. if (w>h[x+1][y]) f[x][y]=max(f[x][y],f[x+1][y]+1);
  35. if (w>h[x][y+1]) f[x][y]=max(f[x][y],f[x][y+1]+1);
  36. }
  37. for (int i=1;i<=r;i++)
  38. for (int j=1;j<=c;j++) ans=max(ans,f[i][j]);
  39. printf("%d",ans+1);
  40. return 0;
  41. }

  

【poj1088】 滑雪的更多相关文章

  1. POJ1088 滑雪

    Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...

  2. POJ1088滑雪(dp+记忆化搜索)

    滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 86411   Accepted: 32318 Description ...

  3. POJ1088滑雪(记忆化搜索+DFS||经典的动态规划)

      Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 84297   Accepted: 31558 Description M ...

  4. POJ1088滑雪

    Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...

  5. [POJ1088] 滑雪(递归dp)

    Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...

  6. POJ-1088 滑雪 (记忆化搜索,dp)

    滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 86318 Accepted: 32289 Description Mich ...

  7. poj1088 滑雪 解题报告

    滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 77423   Accepted: 28779 Description ...

  8. ACM学习历程—POJ1088 滑雪(dp && 记忆化搜索)

    Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...

  9. poj1088滑雪最短路径

    滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 97281   Accepted: 36886 Description ...

  10. 经典DP问题--poj1088滑雪

    Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...

随机推荐

  1. android ant 自动编译打包

    http://www.cnblogs.com/tankaixiong/archive/2010/11/24/1887156.html

  2. Lambda表达式关于like问题(未解决)

    参考文章: http://stackoverflow.com/questions/3616215/like-in-lambda-expression-and-linq 1. c=>c.name. ...

  3. 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 ...

  4. 【Andorid------手势识别】GestureDetector和SimpleOnGestureListener的使用教程(转)——

    FROM:http://www.cnblogs.com/transmuse/archive/2010/12/02/1894833.html 1. 当用户触摸屏幕的时候,会产生许多手势,例如down,u ...

  5. C语言 三级指针的应用

    //三级指针的使用 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #includ ...

  6. oracle系统包—-dbms_output用法

    dbms_output包主要用于调试pl/sql程序,或者在sql*plus命令中显示信息(displaying message)和报表,譬如我们可以写一个简单的匿名pl/sql程序块,而该块出于某种 ...

  7. 一款Android开源的下拉刷新动画

    无意间在GitHub看到的,就Down了下来.但是作者是用AndroidStudio开发的,这边移动Eclipse供小伙伴们下载使用. 截图 这么好的东西因为字数不够不让分享,得了,贴段代码吧 pac ...

  8. WindowsService(Windows服务)开发步骤附Demo

    1.打开VS,新建项目,选择Windows服务,然后设置目录及项目名称后点击确定. 2.展开Service1服务文件,编写service1.cs类文件,不是Service1[设计].然后修改OnSta ...

  9. [MetaHook] Quake OpenGL function

    Quake OpenGL function for MetaHook plugin. Thank hzqst :D QGL.h #ifndef QGL_H #define QGL_H #include ...

  10. Quartz.NET syudy

    Quartz.NET   Quartz.NET是一个开源的作业调度框架,是OpenSymphony 的 Quartz API的.NET移植,它用C#写成,可用于winform和asp.net应用中.它 ...