文章标题
来源:互联网 发布:网络语鹅是什么意思 编辑:程序博客网 时间:2024/06/06 02:26
栈混洗
所谓栈混洗就是序列以某一顺序压入,给定另一个序列看其是否是压入序列的一个输出。用三个栈比较容易理解,A是入栈序列,每次只允许从A中push元素到S或者从S中push元素到A
例如序列1,2,3. 3,2,1就可以是它的一个输出序列,而3 1 2 就不会是它的一个输出序列。对于一个长度为n的序列,其满足栈混洗的数目sp(n)≤n!,具体来说,sp(n)=(2n)!/((n+1)!n!)。
甄别方式就像括号匹配那样按栈混洗的定义来模拟。
#include<iostream>#include<stack>using namespace std;bool IsPopOrder(int pushV[],int popV[],int size) { stack<int> s; int i,j=0; for(i=0;i<size;i++){ s.push(pushV[i]); while(!s.empty()&&s.top()==popV[j]){ s.pop(); j++; } } return s.empty(); }int main(){ int n; cin>>n; int *a=new int [n]; int *b=new int [n]; for(int i=0;i<n;i++){ cin>>a[i]; } for(int j=0;j<n;j++){ cin>>b[j]; } if(IsPopOrder(a,b,n)) cout<<"yes"<<endl; else cout<<"no"<<endl; delete [] a; delete [] b; return 0;}
阅读全文
0 0
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- DES ECB模式JAVA PHP C#实现加密、解密兼容
- RS-232、RS-422与RS-485标准及应用
- i2c底层数据传输解析之RTC实时时钟
- 如何选择合适的机器算法解决问题
- 34. Search for a Range
- 文章标题
- 3DSlicer7:FAQ-1
- Verilog运算符优先级
- Qtmsvc2010+Opencv2.4.9配置
- Python相关链接
- Class JavaLaunchHelper is implemented in both … libinstrument.dylib. One of the two will be used. Wh
- 蒜厂秘籍(map)
- LCD1620
- 分布式ZooKeeper-3.4.10集群安装