宜春市城乡规划建设局网站,苏州快速建站模板,网站开发会用到定时器功能,网站开发英语翻译题意#xff1a;在一个R*c的矩阵上找一条高度严格递减的最长路#xff0c;起点任意#xff0c;每次可以走上下左右。 思路#xff1a;DAG上的最长路问题#xff0c;直接套用记忆化搜索的模板#xff0c;dp#xff08;i#xff0c;j#xff09;max#xff08;dp#…题意在一个R*c的矩阵上找一条高度严格递减的最长路起点任意每次可以走上下左右。 思路DAG上的最长路问题直接套用记忆化搜索的模板dpijmaxdpiijj四个方向最大值然后找出来最大的即可。 code #include bits/stdc.h
using namespace std;using namespace std;typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;const int N1000000;
const int M105;
const int mod1000000007;
const double piacos(-1.0);#define cls(x,c) memset(x,c,sizeof(x))
#define ft(i,s,t) for (int is;it;i)int w,h;
int mp[M][M],dp[M][M];
char s[M];
int tx[]{1,-1,0,0};
int ty[]{0,0,1,-1};
bool ok(int i,int j)
{return (i0iwj0jh);
}
int sol(int i,int j)
{int f0;int ansdp[i][j];if (ans!-1) return ans;ans-1;for (int p0;p4;p){int xitx[p],yjty[p];if (mp[x][y]mp[i][j]ok(x,y)){ansmax(ans,sol(x,y)1);f1;}}if (!f) ans1;return ans;
}
int main()
{int T;scanf(%d,T);while (T--){scanf(%s %d %d,s,w,h);ft(i,0,w-1) ft(j,0,h-1) scanf(%d,mp[i][j]);cls(dp,-1); int ans-1;ft(i,0,w-1) ft(j,0,h-1) ansmax(ans,sol(i,j));printf(%s: %d\n,s,ans);}
}