zoukankan      html  css  js  c++  java
  • POJ 1088 滑雪 记忆化搜索

    解析:状态d[i][j]代表r=i , c=j这个位置能滑的最大长度。深搜+备忘录

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    using namespace std;
    
    const int maxn=100+5;
    int R,C;
    int a[maxn][maxn];
    int d[maxn][maxn];
    int dr[]={0,-1,0,1};
    int dc[]={-1,0,1,0};
    
    int solve(int r,int c)
    {
        if(d[r][c]>0) return d[r][c];
        int next_r,next_c;
        int maxv=0;
        for(int i=0;i<4;i++)
        {
            next_r=r+dr[i];
            next_c=c+dc[i];
            if(next_r<=0 || next_r>R || next_c<=0 || next_c>C)
                continue;
            if(a[r][c]>a[next_r][next_c])
                maxv=max(maxv,solve(next_r,next_c));
        }
        return d[r][c]=maxv+1;
    }
    int main()
    {
        //freopen("in.txt","r",stdin);
        while(cin>>R>>C)
        {
            for(int i=1; i<=R; i++)
                for(int j=1; j<=C; j++)
                    scanf("%d",&a[i][j]);
            memset(d,0,sizeof(d));
            int ans=0;
            for(int i=1;i<=R;i++)
                for(int j=1;j<=C;j++)
                    ans=max(ans,solve(i,j));
            printf("%d
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    作用域链及作用域面试题
    this在js中的作用
    dom对象
    作用域问题
    逻辑运算
    socket.io 的使用
    mongoDB 的使用
    使用 usb 调试的时候,连接上电脑没反应
    uni-app 的更新及碰到的问题
    WebSocket 的使用
  • 原文地址:https://www.cnblogs.com/pach/p/6666296.html
Copyright © 2011-2022 走看看