Cod sursa(job #20361)

Utilizator tudalexTudorica Constantin Alexandru tudalex Data 21 februarie 2007 12:10:55
Problema Perle Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <stdio.h>

int a[10001],n,i,t,max;
int presumec(int x);
int presumeb(int x)
{
	//if (x>max) max=x;
    if (x>n) return 0;
	if (a[x]==2) return presumeb(x+1);
	if (a[x]==1 && a[x+2]==3 && x+4<=n) return presumec(x+4);
	return 0;
}

int presumec(int x)
{
	int r;
	//if (x>max) max=x;
	if (x>n) return 0;
	if (a[x]==1 && a[x+1]==2 && x+1<=n) return x+3;
	if (a[x]==3)
	{
		r=presumeb(x+1);
		if (r!=0) return presumec(r+1); else return 0;
	} 
	if (a[x]==2) return x+1;
	//if (lvl==1  a[x]==2 && n==1) return x+1;
	return 0;
}

int main()
{
	freopen("perle.in","r",stdin);
	freopen("perle.out","w",stdout);
	scanf("%d",&t);
	for (;t>0;--t)
	{
		scanf("%d",&n);
		for (i=1;i<=n;++i) scanf("%d",&a[i]);
		
		if (n==1) printf("1\n"); else
        if (presumeb(1)>=n) printf("1\n"); else
        if (presumec(1)>=n) printf("1\n"); 
        else		
		printf("0\n");
	}
	return 0;
}