题目描述
DP
代码
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
string s;
int n,m,t,d[110][110],a[110][110];
int dp(int i,int j){
int& ans=d[i][j];
if(ans>0) return ans;
ans=1;
if(i+1<n&&a[i+1][j]<a[i][j]) ans=max(ans,dp(i+1,j)+1);
if(j+1<m&&a[i][j+1]<a[i][j]) ans=max(ans,dp(i,j+1)+1);
if(i-1>=0&&a[i-1][j]<a[i][j]) ans=max(ans,dp(i-1,j)+1);
if(j-1>=0&&a[i][j-1]<a[i][j]) ans=max(ans,dp(i,j-1)+1);
return ans;
}
int main(){
int t;
cin>>t;
while(t--){
memset(d,0,sizeof(d));
cin>>s>>n>>m;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
scanf("%d",&a[i][j]);
int ans=0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
ans=max(ans,dp(i,j));
cout<<s<<": "<<ans<<endl;
}
return 0;
}