Pagini recente » Cod sursa (job #1138310) | Cod sursa (job #2537710) | Cod sursa (job #784788) | Cod sursa (job #2782035) | Cod sursa (job #955195)
Cod sursa(job #955195)
#include <fstream>
using namespace std;
ifstream f("nrcuv.in");
ofstream g("nrcuv.out");
const int MAX_N = 1005;
const int SIGMA = 26;
const int MOD = 104659;
int n, m, D[MAX_N][SIGMA + 5];
int possible[SIGMA + 5][SIGMA + 5];
void init() {
for (int i = 0; i < SIGMA + 5; i++)
for (int j = 0; j < SIGMA + 5; j++)
possible[i][j] = 1;
}
void read() {
f >> n >> m;
for (int i = 1; i <= m; i++) {
char c1, c2;
f >> c1 >> c2;
int a = c1 - 'a' + 1;
int b = c2 - 'a' + 1;
possible[a][b] = possible[b][a] = 0;
}
}
void solve() {
for (int i = 1; i <= SIGMA; i++)
D[1][i] = 1;
for (int i = 2; i <= n; i++)
for (int j = 1; j <= SIGMA; j++)
for (int k = 1; k <= SIGMA; k++)
if (possible[j][k]) {
D[i][j] = (D[i][j] + D[i - 1][k]) % MOD;
if (D[i][j] < 0)
D[i][j] += MOD;
}
}
void write() {
int rez = 0;
for (int i = 1; i <= SIGMA; i++) {
rez = (rez + D[n][i]) % MOD;
if (rez < 0)
rez += MOD;
}
g << rez << '\n';
}
int main() {
init();
read();
solve();
write();
f.close();
g.close();
return 0;
}