#include <iostream>
#include <stack>
using namespace std;
int checkedSeq[1010];
stack<int> check;
int main(){
int m,n,k;
//m : 栈最大容量
//n : 序列长度
//k : 检查的序列数
scanf("%d %d %d",&m,&n,&k);
for(int i = 0;i < k;i++){
while(!check.empty()){
check.pop();
}
bool possible = true;
for(int j = 1;j <= n;j++){
scanf("%d",&checkedSeq[j]);
}
int j = 1,p = 1;
check.push(j);
while(!check.empty() || j < n){
if((!check.empty()&&check.top() != checkedSeq[p]) || check.empty()){
j++;
check.push(j);
}else{
p++;
check.pop();
}
if(check.size() > m || (!check.empty() &&check.top() > n)){
possible = false;
break;
}
}
if(possible == false){
if(i == k - 1)
printf("NO");
else
printf("NO\n");
}
else{
if(i == k - 1)
printf("YES");
else
printf("YES\n");
}
}
system("pause");
return 0;
}
PAT | A1051 Pop Sequence
最新推荐文章于 2024-08-12 16:55:46 发布