1051 Pop Sequence (25 分)

2019年2月3日

21:39

#include

#include

#include

#include

using namespace std;

const int maxn = 1005;

int main()

{

    int n, m, k, x[maxn];

    stack 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;

}

你可能感兴趣的:(Pat,甲级)