POJ--1088--dp--滑雪
#include<iostream> using namespace std; const static int N = 102; int map[N][N] = {0}; int mar[N][N] = {0}; int dp(int,int); int row,col; int main() { while(cin>>row>>col) { int i,j; int max = 0; for(i=1;i<=row;++i) for(j=1;j<=col;++j) cin>>map[i][j]; for(i=1;i<=row;++i) for(j=1;j<=col;++j) { if(mar[i][j] == 0)mar[i][j] = dp(i,j); if(max < mar[i][j])max = mar[i][j]; } cout<<max<<endl; } return 0; } int dp(int i,int j) { if(mar[i][j] != 0)return mar[i][j]; int shang=0,xia=0,zuo=0,you=0; if(i-1 >= 1 && map[i-1][j]<map[i][j])shang = 1+dp(i-1,j); else shang = 1; if(i+1 <= row && map[i+1][j]<map[i][j])xia = 1+dp(i+1,j); else xia = 1; if(j-1 >= 1 && map[i][j-1]<map[i][j])zuo = 1+dp(i,j-1); else zuo = 1; if(j+1 <= col && map[i][j+1]<map[i][j])you = 1+dp(i,j+1); else you = 1; shang = shang > xia?shang:xia; shang = shang > zuo?shang:zuo; shang = shang > you?shang:you; return shang; }