2019年2月3日
21:39
#include <iostream>
#include <stack>
#include <algorithm>
#include <cstdio>
using namespace std;
const int maxn = 1005;
int main()
{
int n, m, k, x[maxn];
stack<int> a;
while(cin >> n >> m >> k)
{
for(int i = 0; i < k; i++ )
{
while(!a.empty())
a.pop();
int t = 1, flag = 0;
for(int j = 1; j <= m; j++)
cin >> x[j];
for(int j = 1; j <= m; j++)
{
a.push(j);
if(a.size() > n)
{
flag = 1;
break;
}
while( !a.empty() && a.top() == x[t])
{
a.pop();
t++;
}
}
if(a.size() != 0 || flag)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
}
return 0;
}