Topic Link: Click to open the link
Analytical:
Deep Search. With a vis array, 1 represents the first array, and 0 represents the second array. Generates the first incremented array through DFS, and then examines the second array of the remaining digits.
Complete code:
#include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #include < iostream> #include <cmath> #include <vector> #include <map> #include <stack> using namespace s
td
const int MAXN = 10001;
int A[MAXN];
int VIS[MAXN];
void Dfs (int pre, int cur) {if (cur < && A[pre] < A[cur]) {vis[cur] = 1;
DFS (cur, cur + 1);
else if (cur < && a[pre] > A[cur]) {DFS (PRE, cur + 1);
int main () {#ifdef Doubleq freopen ("In.txt", "R", stdin);
#endif//Doubleq int n;
CIN >> N;
while (n-) {for (int i = 0; i < i + +) {cin >> a[i];
BOOL flag = FALSE;
for (int i = 0; i < i + +) {memset (Vis, 0, sizeof (VIS));
Vis[i] = 1;
DFS (i, i + 1);
int pre = 0;
for (int j = 0; J < J + +) { if (vis[j] = = 0) {if (Pre > A[j]) {flag = true;
Break
else pre = A[j];
} if (!flag) {cout << "YES" << Endl;
Break
} if (flag) cout << "NO" << Endl;
}
}