Cod sursa(job #2492380)

Utilizator mariamirabella2Bucur-Sabau Maria-Mirabela mariamirabella2 Data 14 noiembrie 2019 17:46:19
Problema Lista lui Andrei Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <fstream>

using namespace std;

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

const int Mod=104659;
int n,m,dp[1005][28],sum;
char a,b;
bool mat[28][28];

int main()
{
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a>>b;
        mat[a-'a'][b-'a']=true;
        mat[b-'a'][a-'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(mat[k][j]==false){
                    dp[i][j]+=dp[i-1][k]%Mod;
                    dp[i][j]%=Mod;
                }
            }
        }
    }
    for(int i=0;i<26;i++){
        sum+=dp[n][i];
        sum%=Mod;
    }
    cout<<sum%Mod;
    return 0;
}