【题目链接】
【思路要点】
- 枚举行宽, O ( N ) O(N) O(N) 计算最长河流长度即可。
- 具体来说,可以作为一个空位的前驱的空位至多有 2 2 2 个,且是单调的,因此使用 T w o P o i n t e r s TwoPointers TwoPointers 来进行一个简单 d p dp dp 即可。
- 时间复杂度 O ( N 2 ∣ S ∣ ) O(N^2|S|) O(N2∣S∣) 。
【代码】
#include<bits/stdc++.h> using namespace std; const int MAXN = 2505; typedef long long ll; typedef long double ld; typedef unsigned long long ull; template <typename T> void chkmax(T &x, T y) { x = max(x, y); } template <