Pagini recente » Cod sursa (job #3243586) | Cod sursa (job #3276719) | Cod sursa (job #1976261) | preoni2007_runda2_10 | Cod sursa (job #17074)
Cod sursa(job #17074)
#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);
FOR(i, 0, 2 * N - 2) scanf("%d", &a[i]);
memset(ok, 0xFF, sizeof(ok));
printf("%d\n", fun(0, 2 * N - 2));
return 0;
}