题目传送门:
题解:
//本题主要是栈的应用#include#include using namespace std;int main() { int N, M, K, temp; cin >> N >> M >> K; stack s1; while (K--) { while (!s1.empty()) { s1.pop(); } int f = 1; bool flag = false; for (int i = 0; i < N; i++) { cin >> temp; if (temp == f) { f++; while (!s1.empty()&& s1.top() == f) { s1.pop(); f++; } } else { s1.push(temp); if (s1.size() > M) { flag = true; } } } if (flag||!s1.empty()) { cout << "NO" << endl; } else { cout << "YES" << endl; } } return 0;}