Cod sursa(job #17041)

Utilizator azotlichidAdrian Vladu azotlichid Data 14 februarie 2007 19:46:15
Problema Culori Scor 4
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#define FOR(i, a, b) for (i = (a); i <= (b); i ++)

#define NMAX 512
#define MODULO 9901
typedef long long LL;

int a[NMAX];
int ok[NMAX][NMAX];
int N, i, j, k;

int fun(int b, int e)
{
    if (ok[b][e] != -1)
        return ok[b][e];
    else
    {
        if (b + 1 == e || a[b] != a[e]) return ok[b][e] = 0;
        if (b == e || b + 2 == e) return ok[b][e] = 1;

        int i;
        ok[b][e] = 0;        
        FOR(i, b + 2, e)
            if (a[b] == a[i] && fun(b + 1, i - 1) != 0)
                ok[b][e] = ((LL)ok[b][e] + (LL)fun(b + 1,  i - 1) * (LL)fun(i, e)) % MODULO;
        return ok[b][e];
    }
}

int main(void)
{
    freopen("culori.in", "r", stdin);
    freopen("culori.out", "w", stdout);
    scanf("%d", &N);
    printf("%d\n", N + 1);

    return 0;
}