Cod sursa(job #138321)

Utilizator fireatmyselfBogdan-Alexandru Stoica fireatmyself Data 18 februarie 2008 11:44:50
Problema Nivele Scor 40
Compilator c Status done
Runda Arhiva de probleme Marime 1.16 kb
#include <stdio.h>
#define NMAX 50005

int N, poz, ok, nod=1, it, put = 0;
int F[NMAX];

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

        if (poz>50000) { ok = 0; return; }
        if (poz==1) { ok = 0; return; }

        if (it==N) return;

        if (nv>poz) return;

        if (nv==poz) {
           it++;
           if (it<N) scanf("%d", &poz);
           return;
        }

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

int main()
{
        int i, _case;

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

        scanf("%d", &_case);
        while (_case--)
        {
                scanf("%d%d", &N, &poz);

                nod = ok = 1; it = put = 0;
                df(1,1);

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

                if (it==N&&ok) printf("DA\n");
                else {
                     printf("NU\n");
                     for (i = ++it; i < N; i++) scanf("%d", &ok); }
        }

        return 0;
        
}