Pagini recente » Cod sursa (job #3208801) | Cod sursa (job #597105) | Cod sursa (job #2282820) | Cod sursa (job #2264691) | Cod sursa (job #169479)
Cod sursa(job #169479)
#include <stdio.h>
long int n, v[600], a[600][600], mod;
void citire()
{
freopen("culori.in","r",stdin);
freopen("culori.out","w",stdout);
scanf("%ld",&n);
int i;
for (i = 1; i <= 2 * n - 1; i++) { scanf("%ld",&v[i]); a[i][i] = 1;}
n *= 2; n--;
}
void calcul()
{
mod = 9901;
int i, j, k;
for (i = n; i >= 1; i--)
for (j = n; j >= i; j--)
{
if ((i + j) % 2 == 0)
for (k = i + 1; k < j; k++)
{
if (v[i + 1] == v[k]) a[i][j] += (a[i+1][k] * a[k+1][j]);
a[i][j] %= mod;
}
}
printf("%ld\n",a[1][n]);
}
int main()
{
citire();
calcul();
return 0;
}