http://poj.org/problem?id=1088
校运会放假继续来水一发^ ^
不过又要各种复习,功课拉下了许多 QAQ。
还有呀,就是昨天被一个学姐教育了一番,太感谢了,嘻嘻^ ^
好了,说正事~
题目大意:
中文题吖,就不用我说了哈哈~~~~~~做中文题真舒服,不用开词典^ ^
思路:
搜索的时候显然会有重复的所以采用记忆化搜索。
顺带用了下宏定义,让代码简洁点。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define F(i,R) for(int i=0;i<R;i++)
int a[101][101];
int ans[101][101];
int R,C; int dfs(int r,int c)
{
if(ans[r][c]>0)
return ans[r][c]; int temp=0,res=1;
if(r<R-1 && a[r][c] > a[r+1][c])
res=dfs(r+1,c)+1; if(c<C-1 && a[r][c] > a[r][c+1])
{
temp=dfs(r,c+1)+1;
res = res> temp ? res: temp;
}
if(r>=1 && a[r][c] > a[r-1][c])
{
temp=dfs(r-1,c)+1;
res = res> temp ? res: temp;
}
if(c>=1 && a[r][c] > a[r][c-1])
{
temp=dfs(r,c-1)+1;
res = res> temp ? res: temp;
} return ans[r][c]=res;
} int main()
{
memset(ans,-1,sizeof(ans));
scanf("%d%d",&R,&C);
F(i,R)
F(j,C)
scanf("%d",&a[i][j]); int x=1;
F(i,R)
F(j,C)
{
int temp=dfs(i,j);
x= x > temp? x: temp;
} printf("%d\n",x);
}