Pagini recente » Cod sursa (job #48763) | Cod sursa (job #2251542) | Cod sursa (job #3002037) | Cod sursa (job #650862) | Cod sursa (job #1753065)
#include <iostream>
#include <fstream>
#define NMAX 10003
using namespace std;
int a[NMAX], n, ok;
void expand (int poz, char c)
{
//cout << poz << " " << c << "\n";
if (c == 'B')
{
// cout << "HERE" << poz << "\n";
if (a[poz] == 2 && poz + 1 <= n)
expand (poz + 1, 'B');
if (poz + 4 <= n && a[poz] == 1 && a[poz + 2] == 3)
expand (poz + 4, 'C');
}
if (c == 'C')
{
// cout << "here?";
if (a[poz] == 2 && poz == n)
ok = 1;
if (a[poz] == 1 && a[poz + 1] == 2 && poz + 2 == n)
ok = 1;
if (a[poz] == 3 && poz + 2 <= n)
expand (poz + 2, 'C');
// return 0;
}
// cout << "\n\n";
}
int main()
{
int T;
ifstream cin ("perle.in");
ofstream cout ("perle.out");
cin >> T;
while (T)
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
expand (1, 'B');
if (!ok)
expand (1, 'C');
if (n == 1)
ok = 1;
cout << ok << "\n";
T--;
ok = 0;
}
return 0;
}