Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
第一道深度搜索 一次AC 贴代码 oms#include<stdio.h> int n,m; int c[101][101]; int b[101][101]; int dp(int i,int j) { int sum=0; int l; if(c[i][j]!=0) return c[i][j]; if(i-1>=0&&b[i-1][j]<b[i][j]) { sum=dp(i-1,j); } if(i+1<n&&b[i+1][j]<b[i][j]) { l=dp(i+1,j); if(sum<l) sum=l; } if(j-1>=0&&b[i][j-1]<b[i][j]) { l=dp(i,j-1); if(sum<l) sum=l; } if(j+1<m&&b[i][j+1]<b[i][j]) { l=dp(i,j+1); if(sum<l) sum=l; } return c[i][j]=sum+1; } int main (void) { int i,j; int sum=0,s; scanf("%d %d",&n,&m); for(i=0;i<n;i++) for(j=0;j<m;j++) scanf("%d",&b[i][j]); for(i=0;i<n;i++) for(j=0;j<m;j++) { s=dp(i,j); if(sum<s) sum=s; } printf("%d\n",sum); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator