• POJ 1088


    #include<iostream>
    
    using namespace std;
    
    #include<stdio.h>
    int    dp(int **a,int r,int c,int i,int j,int len,int **p);
     int main(){
        //freopen("1.txt","r",stdin);
        int r;
        int c;
        int i;
        int max = 0;
        int len;
        int k;
           
        int j;
        cin>>r;
        cin>>c;
        len = 1;
        int **a=new int *[r];
        int **p = new int*[r];
        
        for(i = 0; i < r; i++)
        {
               a[i] = new int[c];
               p[i] = new int [c];
        }
         for(i=0;i<r;i++)
             for(j=0;j<c;j++){
                   cin>>a[i][j];
                   p[i][j] = 0;
             }
             for(i = 0; i < r; i++)
                 for(j = 0; j < c; j++)
                 {
                    if(p[i][j] == 0)
                        len += dp(a,r,c,i,j,0,p);
                    else
                        len = p[i][j];
                    if(len > max)
                        max = len;
                    p[i][j] = len;
                //    cout<<len<<endl;
                    len = 1;
                    
                    //cout<<max<<endl;
                 }
       cout<<max<<endl;
         
     }
    
    
    
    int dp(int **a,int r,int c,int i,int j,int len,int **p){
                int max=0;
                if(i-1>=0){
                    len = 0;
                    if(a[i][j]>a[i-1][j]){
                            len++;
                            if(p[i-1][j] == 0)
                            {
                                len += dp(a,r,c,i-1,j,0,p);
                            }
                            else
                            len = p[i-1][j];
                            if(len > max)
                                max = len ;
                    }
                }
                if(j-1>=0){
                    len = 0;
                    if(a[i][j]>a[i][j-1]){
                            len++;
                                if(p[i][j-1] == 0)
                            {
                                len += dp(a,r,c,i,j-1,0,p);
                            }
                            else
                            len =    p[i][j-1];
                            if(len > max)
                                max = len;
                    }
                            
                }
                if(i+1<=r-1){
                    len = 0;
                    if(a[i][j]>a[i+1][j]){
                            len++;
                            if(p[i+1][j] == 0)
                            len +=dp(a,r,c,i+1,j,0,p);
                            else
                                len =p[i+1][j];
                            if(len > max)
                                max = len ;
                    }
                }
                if(j+1<=c-1){
                     len = 0;
                    if(a[i][j]>a[i][j+1]){
                        len++;
                        if(p[i][j+1] == 0)
    
                        len += dp(a,r,c,i,j+1,0,p);
                        else
                            len = p[i][j+1];
                        if(len > max)
                            max = len ;
                    }
                }
                p[i][j] = max;
                p[i][j]++;
                return max;
                
      }  

    关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。 

    技术网站地址: vmfor.com

  • 相关阅读:
    推荐谷歌浏览器12款常用的扩展
    推荐谷歌浏览器12款常用的扩展
    推荐VSCode12个比较实用的插件
    推荐VSCode12个比较实用的插件
    Linux中Shell循环结构for用法笔记
    django之上传图片
    django之中间件设置
    django之admin站点
    django之管理静态文件
    django之设置分页
  • 原文地址:https://www.cnblogs.com/gavinsp/p/4563273.html
Copyright © 2020-2023  润新知