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

题目要求: 一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小。求可以滑落的最长长度。

题目解析:

首先要先排一下序,因为只能高度递减才能滑行。之后就很简单了,就是简单DP。

即:要求的滑坡是一条节点递减并依次相邻的最长路径,可以先根据高度将所有的点进行排序,在i点的时候,遍历0~i-1个点(升序排序,i前面的点的高度一定小于等于i),取相邻点间的大的路径长度

代码如下:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <math.h>
#define N 400
#define inf 0x3f3f3f3f
typedef int ll;
using namespace std;
int tt;
struct node
{
int h,l,w,dp;
}q[];
int cmp(const void *a,const void *b)
{
struct node *aa=(struct node *)a;
struct node *bb=(struct node *)b;
return aa->w-bb->w;
}
int main()
{
int R,C,mat;
while(scanf("%d%d",&R,&C)!=EOF)
{
tt=;
mat=;
for(int i=;i<=R;i++)
{
for(int j=;j<=C;j++)
{
scanf("%d",&q[tt].w);
q[tt].h=i;
q[tt].dp=;//初始值为1
q[tt++].l=j;
}
}
qsort(q,tt,sizeof(q[]),cmp);
for(int i=;i<tt;i++)
{
int rr=q[i].h;
int ll=q[i].l;
for(int j=;j<i;j++)
{
int r2=q[j].h;
int l2=q[j].l;
if((q[i].w>q[j].w)&&((abs(r2-rr)==&&ll==l2)||(rr==r2&&abs(ll-l2)==)))//注意只能高度减小才能滑落,高度相等是不能滑落的
{
q[i].dp=max(q[i].dp,(q[j].dp+));
mat=max(mat,q[i].dp);//不一定节点大的是最大滑落值,自己想一想就知道了,所以要随时记录当前的最大滑落值。
}
}
}
printf("%d\n",mat); }
return ;
}

POJ1088:滑雪(简单dp)的更多相关文章

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

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

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

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

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

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

  4. HDU 1087 简单dp,求递增子序列使和最大

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  5. Codeforces Round #260 (Div. 1) A. Boredom (简单dp)

    题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...

  6. codeforces Gym 100500H A. Potion of Immortality 简单DP

    Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...

  7. 简单dp --- HDU1248寒冰王座

    题目链接 这道题也是简单dp里面的一种经典类型,递推式就是dp[i] = min(dp[i-150], dp[i-200], dp[i-350]) 代码如下: #include<iostream ...

  8. poj2385 简单DP

    J - 简单dp Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     64bit ...

  9. hdu1087 简单DP

    I - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     ...

随机推荐

  1. Appendix A. Common application properties

    Appendix A. Common application properties Prev  Part X. Appendices  Next URl链接:https://docs.spring.i ...

  2. 打开palette面板

  3. SQL Server,MySql,Oracle数据库的默认端口号

    SQL Server默认端口号为:1433 MySQL 默认端口号为:3306 Oracle 默认端口号为:1521

  4. [android] AndroidManifest.xml【 manifest -> uses-permission】

    在  API Level 1 时被引入 简介: 在某些情况下,你为app设置的权限将会影响到google应用商店会用何种规则来过滤你的APP. 如果你需要一个硬件相关的权限——CAMERA,googl ...

  5. 数据库 数据库SQL语句四

    多表查询 等值连接 --查询员工信息,员工号,姓名,月薪,部门名称 select e.empno,e.ename,d.dname from emp e,dept d where e.deptno=d. ...

  6. 关于Unity的C#基础学习(二)

    一.Debug的使用 int a=3; Debug.Log("a="+a); 二.整数的定义 int m; Debug.Log(m);  //C#比C更严谨,没有初始化的变量打印出 ...

  7. 构造方法也可以实现overloading

    构造方法也可以实现overloading.例: public void teach(){}; public void teach(int a){}; public void teach(String ...

  8. zabbix服务器搭建

    zabbix服务器源码安装 参看官方文档 这里不做过多的翻译,我的系统是centos6.5,安装的时候是base安装,所以要装一些其他依赖包,除此之外,还有一些php插件: extension=bcm ...

  9. c#并行扫描端口控制台程序

    static void Main(string[] args) { Console.WriteLine("请输入ip"); string ip = Console.ReadLine ...

  10. Ubantu apt source 国内

    位置 /etc/apt/sources.list apt-get update deb http://mirrors.163.com/ubuntu/ precise main restricted u ...