Pagini recente » Cod sursa (job #1462468) | Cod sursa (job #733468) | Cod sursa (job #2002438) | Cod sursa (job #1557057) | Cod sursa (job #758796)
Cod sursa(job #758796)
#include<fstream>
using namespace std;
int n,m,nr[1001][26];
bool cmp[26][26];
int main()
{
int i,j,k,s=0;
char x1,x2;
ifstream in("nrcuv.in");
ofstream out("nrcuv.out");
in>>n>>m>>ws;
for(i=1;i<=m;i++)
{
in>>x1>>ws>>x2>>ws;
cmp[(int)x1-97][(int)x2-97]=true;
cmp[(int)x2-97][(int)x1-97]=true;
}
for(j=0;j<=25;j++)
nr[1][j]=1;
for(i=2;i<=n;i++)
for(j=0;j<=25;j++)
{
for(k=0;k<=25;k++)
if(!cmp[j][k])
nr[i][j]=nr[i][j]+nr[i-1][k];
nr[i][j]%=104659;
}
for(i=1;i<=n;i++)
{
for(j=0;j<=25;j++)
out<<nr[i][j]<<"\t";
out<<"\n";
}
for(j=0;j<=25;j++)
s=(s+nr[n][j])%104659;
out<<s;
}