这真的是一道动态规划题吗?感觉时间复杂度很高·····
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 10005
int Map[105][105];
int count1[MAX];
int R, C;
int dx[] = { 0,-1,0,1 };
int dy[] = { 1,0,-1,0 };
int DP(int r, int c)
{
for (int i = 0; i < 4; i++)
{
int tr = r + dx[i];
int tc = c + dy[i];
if (tr >= R || tr < 0 || tc >= C || tc < 0)continue;
if (Map[tr][tc] < Map[r][c])
{
count1[r * C + c] = max(DP(tr, tc) + 1, count1[r * C + c]);
}
}
return count1[r * C + c];
}
int main()
{
freopen("sb.txt", "r", stdin);
ios::sync_with_stdio(false);
int casenum;
cin >> casenum;
while (casenum--)
{
memset(Map, 0, sizeof(Map));
string name;
fill(count1, count1 + MAX, 1);
cin >> name;
cin >> R >> C;
for(int i=0;i<R;i++)
for (int j = 0; j < C; j++)
{
cin >> Map[i][j];
}
int ans = -0x3f3f3f3f;
for(int i=0;i<R;i++)
for (int j = 0; j < C; j++)
{
ans = max(ans, DP(i, j));
}
cout << name + ": " << ans << endl;
}
return 0;
}