Pagini recente » Cod sursa (job #1867001) | Cod sursa (job #1110125) | Cod sursa (job #2437279) | Cod sursa (job #2562218) | Cod sursa (job #844388)
Cod sursa(job #844388)
#include <fstream>
#include <bitset>
#define MOD 104659
using namespace std;
const char iname[] = "nrcuv.in";
const char oname[] = "nrcuv.out";
ifstream fin(iname);
ofstream fout(oname);
int N , M , i , sol;
char l1 , l2 , j , lc;
int DP[ 1004 ][ 164 ];
bitset < 164 > mark[ 164 ];
int main()
{
fin >> N >> M;
for (i = 1; i <= M; ++i)
{
fin >> l1 >> l2;
mark[l1][l2] = 1;
mark[l2][l1] = 1;
}
for (j = 'a'; j <= 'z'; ++j)
DP[1][j] = 1;
for (i = 1; i <= N; ++i)
{
for (j = 'a'; j <= 'z'; ++j)
{
for (lc = 'a'; lc <= 'z'; ++lc)
{
if (!mark[j][lc])
{
DP[i][j] = (DP[i - 1][lc] + DP[i][j]) % MOD;
}
}
}
}
for (j = 'a'; j <= 'z'; ++j)
sol = (sol + DP[N][j]) % MOD;
fout << sol << '\n';
return 0;
}