zoukankan      html  css  js  c++  java
  • hdu1078 记忆化搜索

    /*
    hdu 1078
    QAQ记忆化搜索 其实还是搜索。。因为里面开了一个数组这样可以省时间 (dp【x】【y】大于0就不用算了直接返回值)
    */
    
    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    int n,l;
    int m[105][105];
    int dp[105][105];
    int dx[]={1,0,-1,0};
    int dy[]={0,1,0,-1};
    bool check(int x,int y)
    {
        if(x>=0&&x<n&&y>=0&&y<n)
            return true;
        else return false;
    }
    int dfs(int xx,int yy)
    {
        int st=0;
        int x,y;
        int temp;
        if(dp[xx][yy]<0)
        {
    
    
        for(int i=0;i<4;i++)
        {
            for(int k=1;k<=l;k++)
            {
                x=xx+dx[i]*k;
                y=yy+dy[i]*k;
                if(check(x,y)&&m[x][y]>m[xx][yy])
                {
                    temp=dfs(x,y);
                    if(temp>st)
                        st=temp;
                }
            }
        }
        dp[xx][yy]=st+m[xx][yy];
        }
        return dp[xx][yy];
    }
    int main(){
    while(~scanf("%d%d",&n,&l))
    {
        if(n==-1&&l==-1)
            break;
        for(int i=0;i<n;i++)
        {
            for(int k=0;k<n;k++)
            {
                scanf("%d",&m[i][k]);
            }
        }
        int maxx=-2;
        memset(dp,-1,sizeof(dp));
        printf("%d
    ",dfs(0,0));
    }
    }
  • 相关阅读:
    SQL SEREVR IO
    INTEL
    windows performance
    The DiskSpd Storage Performance Tool
    machine Learning
    NOSQL
    X64 Deep Dive
    Debugging and performance,ETW
    Disk Performance
    WCF transport-and-message-security
  • 原文地址:https://www.cnblogs.com/rayrayrainrain/p/5181919.html
Copyright © 2011-2022 走看看