- 贪心
- 注意就算从n就能看出答案,也要让它先输入完成
- cnt表示栈内待被匹配的点的数量
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int _;
cin >> _;
while (_ -- )
{
int n;
cin >> n;
int cnt = 1;
int ai;
for (int i = 2; i <= n; i ++ )
{
cin >> ai;
if (ai == 2) cnt ++ ;
else
{
if (!cnt) cnt ++ ;
else cnt -- ;
}
}
if (n & 1 || cnt) cout << "No" << endl;
else cout << "Yes" << endl;
}
return 0;
}