PAT 1051

来源:互联网 发布:国内数据库厂商 编辑:程序博客网 时间:2024/04/30 23:23
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<stack>using namespace std;int main(){stack<int> st;int m,n,k;int cmp[1010];scanf("%d%d%d",&m,&n,&k);while(k--){while(!st.empty())st.pop();for(int i=1;i<=n;i++){scanf("%d",&cmp[i]);}int current=1;bool flag=true;for(int i=1;i<=n;i++){st.push(i);if(st.size()>m){flag=false;break;}while(!st.empty()&&st.top()==cmp[current]){st.pop();current++;}}if(st.empty()==true&&flag==true){printf("YES\n");}elseprintf("NO\n");}system("pause");return 0;}

0 0
原创粉丝点击