本文主要是介绍POJ-1088 滑雪 记忆化搜索,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接
#include <stdio.h>
#include <string.h>
#include <iostream>
#include<functional>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;
const int maxn = 105;
int n,m;
int map[maxn][maxn],dp[maxn][maxn];
int xs[] = {0,1,0,-1};
int ys[] = {1,0,-1,0};
void dfs( int x,int y )
{if( dp[x][y] != -1 )return;dp[x][y] = 1;int Max = 0,xx,yy;for( int i = 0; i < 4; i ++ ){xx = x + xs[i];yy = y + ys[i];if( xx >= 1 && xx <= n && yy >= 1 && yy <= m && map[xx][yy] < map[x][y] ){dfs( xx,yy );Max = max( Max,dp[xx][yy] );}}dp[x][y] += Max;
}
int main()
{#ifndef ONLINE_JUDGE freopen("data.txt","r",stdin); #endif while( scanf("%d%d",&n,&m) != EOF ){memset( dp,-1,sizeof(dp) );for( int i = 1; i <= n; i ++ )for( int j = 1; j <= m; j ++ )scanf("%d",&map[i][j]);int ans = 0;for( int i = 1; i <= n; i ++ ){for( int j = 1; j <= m; j ++ ){dfs(i,j);ans = max( ans,dp[i][j] );}}printf("%d\n",ans);}return 0;
}
这篇关于POJ-1088 滑雪 记忆化搜索的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!