Pagini recente » Cod sursa (job #2680593) | Cod sursa (job #552603) | Cod sursa (job #2386895) | Cod sursa (job #1906236) | Cod sursa (job #1164573)
#include<fstream>
using namespace std;
ifstream in("nrcuv.in");
ofstream out("nrcuv.out");
int s,n,m,a[30][30],dp[1009][30];
int main()
{
char x,y;
in>>n>>m;
for(int i=1;i<=m;i++)
{
in>>x>>y;
a[x-'a'+1][y-'a'+1]=a[y-'a'+1][x-'a'+1]=1;
}
for(int i=1;i<=26;i++) dp[1][i]=1;
for(int i=2; i<=n; i++)
{
for(int j=1; j<=26; j++)
{
for(int k=1; k<=26; k++)
if(a[k][j]==0)
dp[i][j]+=dp[i-1][k];
}
}
for(int i=1;i<=26 ;i++)
s+=dp[n][i];
out<<s<<'\n';
out.close();
return 0;
}