zoukankan      html  css  js  c++  java
  • (DP6.1.4.2)POJ 1088 滑雪

    其实下面用到的是搜索。(呜呜,DP写的过了测试用例但是却总是AC不了,所以改用搜索来做了)


    /*
     * POJ_1088.cpp
     *
     *  Created on: 2013年10月13日
     *      Author: Administrator
     */
    
    #include <iostream>
    #include <cstdio>
    
    using namespace std;
    
    const int maxn = 110;
    
    int a[maxn][maxn];
    int d[maxn][maxn];
    int dir[4][2] = {{1,0},{-1,0},{0,1},{0,-1} };
    
    int r,c;
    void run(int x,int y){
    	if(d[x][y] > 0){
    		return ;
    	}
    
    	d[x][y] = 1;
    
    	int i,j;
    
        for(i = 0 ; i < 4 ; ++i){
        	int xx = x + dir[i][0];
        	int yy = y + dir[i][1];
    
        	if(xx >= 0 && xx <r && yy >= 0 && yy < c && a[xx][yy] < a[x][y]){
    
        		run(xx,yy);
    
        		if(d[xx][yy] + 1 > d[x][y]){
        			d[x][y] = d[xx][yy] + 1;
        		}
        	}
        }
    }
    
    
    int main(){
    	while(scanf("%d%d",&r,&c)!=EOF){
    
    		int i,j;
    		for(i = 0 ; i < r ; ++i){
    			for(j = 0 ; j < c ; ++j){
    				scanf("%d",&a[i][j]);
    			}
    		}
    
    		int maxStep = 0;
    		for(i = 0 ; i < r; ++i){
    			for(j = 0 ; j < c ; ++j){
    				if(d[i][j] == 0){
    					run(i,j);
    
    					if(d[i][j] > maxStep){
    						maxStep = d[i][j];
    					}
    				}
    
    
    			}
    		}
    
    		printf("%d
    ",maxStep);
    	}
    
    	return 0;
    }
    


  • 相关阅读:
    Python常见的几种算法
    Python的八种数据类型
    网络协议
    Python基本知识
    Python简介
    Windows10 java环境配置
    linux 为动态分配的Virtualbox虚拟硬盘扩容
    ubuntu 18.04.1安装hadoop3.1.2
    linux 安装virtualbox5.2
    这是写给我自己看的!!
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3367711.html
Copyright © 2011-2022 走看看