#include <cstdio>
#include <stack>
using namespace std;
int ans[1001];
stack<int> st;
int main()
{
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
for(int i=0;i<k;i++)
{
while(!st.empty())
st.pop();
for(int j=1;j<=m;j++)
scanf("%d",&ans[j]);
//current表示当前下标
int current=1;
//flag为false表示栈溢出
bool flag=true;
for(int j=1;j<=m;j++)
{
st.push(j);
if(st.size()>n)
{
flag=false;
break;
}
while(!st.empty()&&st.top()==ans[current])
{
st.pop();
current++;
}
}
if(st.empty()==true&&flag==true)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
PAT 1051 Pop Sequence (25 分)
最新推荐文章于 2020-02-09 14:24:21 发布