zoukankan      html  css  js  c++  java
  • POJ1088(滑雪)

    题目链接

    动态规划题。

    题目大意:给定一个二维数组,数组中每个数代表一个高度,每次只能向相邻且高度下降的方向移动,求最长的移动距离。

    View Code
     1 #include <stdio.h>
     2 #include <memory.h>
     3 #define MAX(a,b) ((a)>(b)?(a):(b))
     4 #define N 100
     5 int dx[4]={0,0,1,-1};
     6 int dy[4]={1,-1,0,0};
     7 int h[N][N],n,m;
     8 int c[N][N];
     9 int dp(int i,int j)
    10 {
    11   int ni,nj,d;
    12   if(c[i][j]) return c[i][j];
    13   c[i][j]=1;
    14   for(d=0;d<4;d++)
    15   {
    16     ni=i+dx[d],nj=j+dy[d];
    17     if(ni<0 || nj<0 || ni>=n || nj>=m || h[ni][nj]>=h[i][j])  continue;
    18     c[i][j]=MAX(c[i][j],dp(ni,nj)+1);
    19   }
    20   return c[i][j];
    21 }
    22 int main()
    23 {
    24   int i,j,ans;
    25   while(~scanf("%d%d",&n,&m))
    26   {
    27     for(i=0;i<n;i++)
    28     {
    29       for(j=0;j<m;j++)  scanf("%d",&h[i][j]);
    30     }
    31     ans=1;
    32     for(i=0;i<n;i++)
    33     {
    34       for(j=0;j<m;j++)  ans=MAX(ans,dp(i,j));
    35     }
    36     printf("%d\n",ans);
    37     memset(c,0,sizeof(c));
    38   }
    39   return 0;
    40 } 
  • 相关阅读:
    Android6.0权限组申请
    Win10安装程序出现error code 2502 2503
    StartUML2.8破解
    Batchsize与learning rate
    Tensorflow 多gpu训练
    centos7系统时间修复
    服务器安装小结
    caffe与tensorflow中的pooling
    MixConv
    blazeFace
  • 原文地址:https://www.cnblogs.com/algorithms/p/2469695.html
Copyright © 2011-2022 走看看