Pagini recente » Cod sursa (job #3193210) | Cod sursa (job #1417509) | Cod sursa (job #575203) | Borderou de evaluare (job #1520887) | Cod sursa (job #568154)
Cod sursa(job #568154)
#include<fstream>
#define mod 104659
#define dmax 1003
#define nrl 30
using namespace std;
ifstream in("nrcuv.in");
ofstream out("nrcuv.out");
int n,mat[dmax][nrl],sol,m;
bool t[nrl][nrl];
int main()
{
int i,j,k;
char a,b;
in>>n>>m;
for(i=1;i<=m;i++)
{
in>>a>>b;
t[a-'a'][b-'a'] = t[b-'a'][a-'a'] = 1;
}
in.close();
for(i=0;i<=25;i++)
mat[1][i]=1;
for(i=2;i<=n;i++)
for(j=0;j<=25;j++)
{
for(k=0;k<=25;k++)
if(!t[j][k])
{
mat[i][j]+=mat[i-1][k];
if(mat[i][j] >= mod)
mat[i][j] %= mod;
}
if(i==n)
{
sol+=mat[i][j];
if(sol > mod)
sol %= mod;
}
}
out<<sol;
out.close();
return 0;
}