本文主要是介绍洛谷-P1434,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
滑雪
#include <iostream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;const int dirx[] = { 1,-1,0,0 };
const int diry[] = { 0,0,1,-1 };
const int MAXSIZE = 1e2 + 7;int dp[MAXSIZE][MAXSIZE] = { 0 }, arr[MAXSIZE][MAXSIZE] = { 0 };
int ret = 0, n = 0, m = 0;//从当前节点 最多走多少步
int dfs(int x,int y) {if (dp[x][y]) return dp[x][y];int t = arr[x][y],nCount = 1;for (int i = 0; i < 4; ++i) {int nex = x + dirx[i];int ney = y + diry[i];if(nex < 0 || ney < 0 || nex >=n || ney >= m ) continue;if(t <= arr[nex][ney]) { continue;}//只往比当前小的走 所以无法回头 不需要额外的递归终止条件 走不了就终止了nCount = max(nCount, dfs(nex, ney) + 1);}return nCount;
}
int main()
{cin >> n >> m;for (int i = 0; i < n; ++i) {for (int j = 0; j < m; ++j)cin >> arr[i][j];}for (int i = 0; i < n; ++i) {for (int j = 0; j < m; ++j) {dp[i][j] = dfs(i, j);ret = max(ret, dp[i][j]);}}cout << ret << endl;return 0;
}
这篇关于洛谷-P1434的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!