Pagini recente » Cod sursa (job #3187271) | Sopterean Adrian | Cod sursa (job #3249558) | Cod sursa (job #1756350) | Cod sursa (job #3249105)
#include<bits/stdc++.h>
using namespace std;
ifstream fin("nrcuv.in");
ofstream fout("nrcuv.out");
const int MOD = 104659;
const int SIGMA = 26;
int n, m, s, adj[SIGMA], dp[1005][SIGMA]; //dp[i][j] = nr de cuvinte de lungime i cu ultima litera j care se pot forma
char a, b;
int main(){
fin >> n >> m;
for(;m--;){
fin >> a >> b;
a -= 'a';
b -= 'a';
adj[a] |= (1 << b);
adj[b] |= (1 << a);
}
for(int i = 0; i < SIGMA; ++i)
dp[1][i] = 1;
for(int i = 2; i <= n; ++i)
for(int j = 0; j < SIGMA; ++j)
for(int bit = 0; bit < SIGMA; ++bit)
if(!(adj[j] & (1 << bit))){
dp[i][j] += dp[i - 1][bit];
if(dp[i][j] >= MOD)
dp[i][j] -= MOD;
}
for(int i = 0; i < SIGMA; ++i)
s += dp[n][i];
fout << s % MOD;
}