Cod sursa(job #332765)

Utilizator ssergiussSergiu-Ioan Ungur ssergiuss Data 19 iulie 2009 18:06:03
Problema Lista lui Andrei Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
# include <algorithm>
using namespace std;

# define ALF 27
# define DIM 1001
# define MOD 104659

int n, m, a[ ALF ][ ALF ], sol[ DIM ][ ALF ];

inline int cod ( char ch ) {

    return ch - 'a' + 1;
}

void solve () {

    int i, j, k;
    char s[ 4 ];

    scanf ( "%d%d\n", &n, &m );
    for ( i = 0; i < m; ++ i ) {

        gets ( s );
        a[ cod ( s[ 0 ] ) ][ cod ( s[ 2 ] ) ] = -1;
        a[ cod ( s[ 2 ] ) ][ cod ( s[ 0 ] ) ] = -1;
    }
    for ( i = 1; i < ALF; ++ i )
        sol[ 1 ][ i ] = 1;
    for ( i = 2; i <= n; ++ i )
        for ( j = 1; j < ALF; ++ j )
            for ( k = 1; k < ALF; ++ k )
                if ( !a[ j ][ k ] )
                    sol[ i ][ j ] = ( sol[ i ][ j ] + sol[ i - 1 ][ k ] ) % MOD;
    for ( i = 2; i < ALF; ++ i )
        sol[ n ][ i ] = ( sol[ n ][ i ] + sol[ n ][ i - 1 ] ) % MOD;
    printf ( "%d", sol[ n ][ ALF -1 ] );
}

int main () {

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

    solve ();

    return 0;
}