浙大データ構造02-リニア構造4 Pop Sequence(25分)
1533 ワード
02-線形構造4 Pop Sequence(25分)
Given a stack which can keep M numbers at most.Push N numbers in the ordes of 1,2,3,…,N and pop radomly. You ararsupposed to tell ifea given sequence of numbes isa possible posible pop sequence of FoForeck.Forever.Foreck.5.Forever.aaable.Foreck.5.fs.Foreck.aaaable.5.fs.s.fs.s.s.s.s.aaaaaaap SeSepapapapapapapapapapapapapapapapapapapapapapapapat 3,2,1,7,5,6,4.
Input Specification:
Each input file contains one test case.For each case,the first line contains 3 numbers,and K.The n_K lines follow、each contains a pop sequence of N numbers.All the numbers in a line e e e separated by a space.
Output Specification:
For each pop sequence,print in one line“YES”if it is indeed a possible pop sequence of the stack,or“NO”if not.
Sample Input:
Given a stack which can keep M numbers at most.Push N numbers in the ordes of 1,2,3,…,N and pop radomly. You ararsupposed to tell ifea given sequence of numbes isa possible posible pop sequence of FoForeck.Forever.Foreck.5.Forever.aaable.Foreck.5.fs.Foreck.aaaable.5.fs.s.fs.s.s.s.s.aaaaaaap SeSepapapapapapapapapapapapapapapapapapapapapapapapat 3,2,1,7,5,6,4.
Input Specification:
Each input file contains one test case.For each case,the first line contains 3 numbers,and K.The n_K lines follow、each contains a pop sequence of N numbers.All the numbers in a line e e e separated by a space.
Output Specification:
For each pop sequence,print in one line“YES”if it is indeed a possible pop sequence of the stack,or“NO”if not.
Sample Input:
5 7 5
1 2 3 4 5 6 7
3 2 1 7 5 6 4
7 6 5 4 3 2 1
5 6 4 3 7 2 1
1 7 6 5 4 3 2
Sample Output:YES
NO
NO
YES
NO
#include
#include
using namespace std;
int m,n,k;
int check(int *a){
int capacity=m+1;
stack sta;
int i=0;
int num=1;
sta.push(0);
while(ista.top()&&sta.size()>m>>n>>k;
int data[n];
for(int i=0;i>val;
data[j]=val;
}
if(check(data))
cout<