栈模拟
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <stack> using namespace std; #define maxn 1005 int n; int f[maxn]; void input() { for (int i = 1; i < n; i++) scanf("%d", &f[i]); } bool ok() { stack<int> stk; int temp = 1; for (int i = 0; i < n; i++) { while (temp <= f[i]) stk.push(temp++); int x = stk.top(); stk.pop(); if (x != f[i]) return false; } return true; } int main() { //freopen("t.txt", "r", stdin); while (scanf("%d", &n), n) { while (scanf("%d", &f[0]), f[0]) { input(); if (ok()) puts("Yes"); else puts("No"); } puts(""); } return 0; }