题解
数组模拟栈
C++ 代码
#include <iostream>
#include <cstring>
using namespace std;
const int N = 1010;
int n, m, k;
int main()
{
cin >> m >> n >> k;
while (k -- )
{
int stk[N];
int a[N];
int tt = 0;
stk[tt] = 1;
bool res = true;
for (int i = 0, j = 1; i < n; i ++ )
{
cin >> a[i];
while ((tt == -1 || stk[tt] < a[i]) && tt < m)
{
stk[ ++ tt] = j ++ ;
}
if (stk[tt] == a[i])
{
tt -- ;
}
else res = false;
}
if (res) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}