#include<iostream>
using namespace std;
#include<vector>
struct arr
{
int num[100];
};
class store
{
vector<arr> vt;
public:
int *getmn(int m,int n)
{
return &(vt.at(m-1).num[n-1]);
}
void push_back()
{
vt.push_back(*new arr);
}
};
store str;int R,C;
int step(int x,int y,int height);
int main()
{
int i,j,b,c;
cin>>R>>C;
for(i=1;i<=R;i++)
{
str.push_back();
for(j=1;j<=C;j++)
{
cin>>*str.getmn(i,j);
}
}
cout<<endl<<step(1,1,0)+1<<endl;
return 0;
}
int step(int x,int y,int height)
{
int a,b,c,d,e;
if(x>R||y>C||x<1||y<1) return -1;
if(height>*str.getmn(x,y)) return -1;
a=*str.getmn(x,y);
b=step(x,y+1,0);
if(b<(c=step(x+1,y,a))) b=c;
if(b<(d=step(x,y-1,a))) b=d;
if(b<(e=step(x-1,y,a))) b=e;
return (1+b);
}
测试数据:
5 5
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
程序也没进入死循环
为什么不打印step(1,1,0)
我明明写了cout<<step(1,1,0)