judgejudge @ 2019-02-24 12:53:01
#include <iostream>
using namespace std;
int a[101][101];
int f[101][101];
int n,m;
int dp(int s1,int s2){
int i,j;
if(s1>=1&&s1<=n&&s2>=1&&s2<=m){
if(a[s1-1][s2]<a[s1][s2]){
f[s1-1][s2]=max(f[s1-1][s2],f[s1][s2]+1);
dp(s1-1,s2);
}
if(a[s1+1][s2]<a[s1][s2]){
f[s1+1][s2]=max(f[s1+1][s2],f[s1][s2]+1);
dp(s1+1,s2);
}
if(a[s1][s2-1]<a[s1][s2]){
f[s1][s2-1]=max(f[s1][s2-1],f[s1][s2]+1);
dp(s1,s2-1);
}
if(a[s1][s2+1]<a[s1][s2]){
f[s1][s2+1]=max(f[s1][s2+1],f[s1][s2]+1);
dp(s1,s2+1);
}
}
}
int main(){
int i,j,k;
int row,col;
int maxl=0;
cin>>n>>m;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++){
cin>>a[i][j];
if(a[i][j]>maxl){
maxl=a[i][j];
row=i;
col=j;
}
}
maxl=0;
f[row][col]=1;
dp(row,col);
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
if(maxl<f[i][j])maxl=f[i][j];
cout<<maxl;
return 0;
}
能帮帮我优化一下吗???
by aminoas @ 2019-02-24 16:09:18
好吧,我用深搜做出来了@judgejudge
by judgejudge @ 2019-02-24 16:27:15
@2018J1605 怎么做的???
by aminoas @ 2019-02-24 16:28:52
加了一发记忆化
@judgejudge
by aminoas @ 2019-02-24 16:30:04
你去看看那道题的提交记录就会发现有一页半都是我的...
by judgejudge @ 2019-02-24 16:33:05
@2018J1605 我知道要加记忆化,问题是我这个程序我不知道在哪改比较好 qwq
by aminoas @ 2019-02-24 16:58:05
@judgejudge
把从高往低搜换成从低往高搜就好了。
因为这样就不用更新答案了。
by judgejudge @ 2019-02-24 18:57:49
@2018J1605 哦哦,棒极了!!!
by aminoas @ 2019-02-24 19:03:00
还是题解给了我思路
by ⚡GG⚡ @ 2019-02-26 14:29:10
@ 您的用户名……