zoukankan      html  css  js  c++  java
  • poj 1088 dp **

    链接:点我

    记忆化搜索很好写

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<cmath>
     6 #include<queue>
     7 #include<map>
     8 using namespace std;
     9 #define MOD 1000000007
    10 const int INF=0x3f3f3f3f;
    11 const double eps=1e-5;
    12 typedef long long ll;
    13 #define cl(a) memset(a,0,sizeof(a))
    14 #define ts printf("*****
    ");
    15 const int MAXN=1005;
    16 int n,m,tt;
    17 int a[MAXN][MAXN];
    18 int dp[MAXN][MAXN];
    19 int d[4][2]={1,0,0,1,-1,0,0,-1};
    20 int fun(int x,int y)
    21 {
    22     if(dp[x][y]>0)    return dp[x][y];
    23     dp[x][y]=1;
    24     for(int i=0;i<4;i++)
    25     {
    26         int nx=x+d[i][0];
    27         int ny=y+d[i][1];
    28         if(nx>=1&&nx<=n&&ny>=1&&ny<=m&&a[x][y]>a[nx][ny])
    29         {
    30             if(dp[x][y]<fun(nx,ny)+1)
    31                 dp[x][y]=dp[nx][ny]+1;
    32         }
    33     }
    34     return dp[x][y];
    35 }
    36 int main()
    37 {
    38     int i,j,k;
    39     #ifndef ONLINE_JUDGE
    40     freopen("1.in","r",stdin);
    41     #endif
    42     while(scanf("%d%d",&n,&m)!=EOF)
    43     {
    44         for(i=1;i<=n;i++)
    45         {
    46             for(j=1;j<=m;j++)
    47             {
    48                 scanf("%d",&a[i][j]);
    49             }
    50         }
    51         memset(dp,-1,sizeof(dp));
    52         int ans=0;
    53         for(i=1;i<=n;i++)
    54             for(j=1;j<=m;j++)
    55             {
    56                 if(fun(i,j)>ans) ans=dp[i][j];
    57             }
    58         printf("%d
    ",ans);
    59     }
    60 }
  • 相关阅读:
    Dom页面加载
    Redis
    Ubuntu下git的安装与使用
    类Xadmin插件--海豚插件
    Python基础指随笔
    前端必须掌握30个CSS3选择器
    SweetAlert插件示例
    Pylint在项目中的使用
    django Cookie、Session和自定义分页
    django创建超级用户
  • 原文地址:https://www.cnblogs.com/cnblogs321114287/p/4636195.html
Copyright © 2011-2022 走看看