Cod sursa(job #137619)

Utilizator fireatmyselfBogdan-Alexandru Stoica fireatmyself Data 17 februarie 2008 12:49:15
Problema Nivele Scor 50
Compilator c Status done
Runda preONI 2008, Runda 4, Clasele 11-12 Marime 1.15 kb
#include <stdio.h>
#define NMAX (1<<16)

int N, V[NMAX], F[NMAX], St[NMAX], poz, ok, nod=1;

int df(int i, int nv)
{
        int j;

        if (poz==N) return;

        if (nv>V[poz]) return;

        if (nv==V[poz]) {
           poz++;
           return;
        }

        St[nv] = i;
        while (F[i]<2&&V[poz]>nv&&poz<N) {
           F[i]++; df(++nod, nv+1); }
}

int main()
{
        int i, j, _case;

        freopen("nivele.in", "r", stdin);
        freopen("nivele.out", "w", stdout);

        scanf("%d", &_case);
        while (_case--)
        {
                scanf("%d", &N);
                ok = 1;
                for (i = 0; i < N; i++) { scanf("%d", V+i);
                if (V[i]>50000) ok==0; }

                V[N] = -1;

                if ((ok==0)||(N>1&&V[i]==1)) { printf("NU\n"); continue; }

                ok = V[0]; poz = 0; nod = 1;
                df(1,1);

                for (i = ok = 1; i <= nod; i++)
                {
                    if (F[i]==1) ok = 0;
                    F[i] = 0;
                }

                if (poz==N&&ok) printf("DA\n");
                else printf("NU\n");
        }

        return 0;
        
}