PAT甲级1051 Pop Sequence (25 分)

模拟

#include<iostream>
#include<stack>
using namespace std;
const int N=10010;
int a[N];

int m,n,k;
int chech()
{
    
    
    stack<int> stk;
    for(int i=1,j=0;i<=n;i++)
    {
    
    
        stk.push(i);
        if(stk.size()>m)return 0;
        while(stk.size() && stk.top()==a[j]){
    
    
            stk.pop();
            j++;
        }
    }
    return stk.empty();
}

int main()
{
    
    
    cin>>m>>n>>k;
    while(k--)
    {
    
    
        for(int i=0;i<n;i++)cin>>a[i];
        if(chech())cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_51928751/article/details/121385331