Pagini recente » Cod sursa (job #2871241) | Cod sursa (job #2390086) | Cod sursa (job #698150) | Cod sursa (job #2730524) | Cod sursa (job #2926325)
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
using ll = long long;
using namespace std;
const int NMAX = 1005;
const int MOD = 104659;
/*******************************/
// INPUT / OUTPUT
ifstream f("nrcuv.in");
ofstream g("nrcuv.out");
/*******************************/
/// GLOBAL DECLARATIONS
int N, M;
int ans;
bool ok[26][26];
int dp[26][NMAX];
/*******************************/
/// FUNCTIONS
void ReadInput();
void Solution();
void Output();
/*******************************/
///-------------------------------------
inline void ReadInput()
{
f >> N >> M;
memset(ok, true, sizeof(ok));
char a, b;
for (int i = 1 ; i <= M ; ++ i)
{
f >> a >> b;
ok[a - 'a'][b - 'a'] = ok[b - 'a'][a - 'a'] = 0;
}
}
///-------------------------------------
inline void Solution()
{
for (int ch = 0 ; ch < 26 ; ++ ch)
dp[ch][1] = 1;
for (int len = 2 ; len <= N ; ++ len)
{
for (int ch = 0 ; ch < 26 ; ++ ch)
{
for (int prev_ch = 0 ; prev_ch < 26 ; ++ prev_ch)
{
if (!ok[ch][prev_ch]) continue;
dp[ch][len] += dp[prev_ch][len - 1];
if (dp[ch][len] >= MOD)
dp[ch][len] -= MOD;
}
}
}
for (int ch = 0 ; ch < 26 ; ++ ch)
{
ans += dp[ch][N];
if (ans >= MOD)
ans -= MOD;
}
}
///-------------------------------------
inline void Output()
{
g << ans;
}
///-------------------------------------
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ReadInput();
Solution();
Output();
return 0;
}