P383 One Way In, Two Ways Out

One Way In, Two Ways Out

题目描述

Consider a special queue which is a linear structure that allows insertions at one end, yet deletions at both ends. Your job is to check, for a given insertion sequence, if a deletion sequence is possible. For example, if we insert 1,2,3,41, 2, 3, 4 and 55 in order, then it is possible to obtain 1,3,2,51, 3, 2, 5 and 44 as an output, but impossible to obtain 5,1,3,25, 1, 3, 2 and 44.

输入格式

Each input file contains one test case. For each case, the first line gives 22 positive integers NN and KK (10≤10), which are the number of insertions and the number of queries, respectively. Then NN distinct numbers are given in the next line, as the insertion sequence. Finally KK lines follow, each contains NN inserted numbers as the deletion sequence to be checked.

🔒
登录后查看完整题面
登录后查看题目

统计