Cod sursa(job #2492420)

Utilizator Vlad_PipereaPiperea Vlad Vlad_Piperea Data 14 noiembrie 2019 18:47:11
Problema Lista lui Andrei Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <iostream>
#include <fstream>
#include <cstring>

using namespace std;

ifstream in("nrcuv.in") ;
ofstream out("nrcuv.out") ;

const int N = 1001 ;
const int M = 104659;
int dp[N][26], n, m, suma = 0 ;

bool a[26][26] ;

int main()
{
    char x, y ;
    in >> n >> m ;
    for(int i = 0 ; i < m ; i++ )
    {
        in >> x >> y ;
        a[x - 'a'][y - 'a'] = a[y - 'a'][x - 'a'] = true ;
    }
    for( int j = 0 ; j < 26 ; j++ )
    {
        dp[1][j] = 1;
    }
    for( int i = 2 ; i <= n ; i++ )
    {
        for( int j = 0 ; j < 26 ; j++ )
        {
            for( int k = 0 ; k < 26 ; k++ )
            {
                if( !a[k][j] )
                {
                    dp[i][j] += dp[i-1][k] ;
                    dp[i][j] %= M;
                }
            }
        }
    }
    for( int j = 0 ; j < 26 ; j++ )
    {
        suma = suma + dp[n][j] ;
        suma %= M;
    }
    out << suma ;
    return 0;
}