Cod sursa(job #833142)

Utilizator ericptsStavarache Petru Eric ericpts Data 11 decembrie 2012 22:36:42
Problema Lista lui Andrei Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <cstdio>
using namespace std;
#define mod 104659
bool g['z'+1]['z'+1];
int best[1001]['z'+2];
int main()
{
    freopen("nrcuv.in","r",stdin);
    freopen("nrcuv.out","w",stdout);
    int n,k;
    char x,y;
    int i;
    int show;
    char j;
    char p;
    scanf("%d %d\n",&n,&k);
    while(k--)
    {
        scanf("%c %c\n",&x,&y);
        g[x][y]=1;
        g[y][x]=1;
    }
    for(i='a';i<='z';++i)
        best[1][i]=1;
    for(i=1;i<=n;++i)
        for(j='a';j<='z';++j)
            for(p = 'a';p <= 'z';++p)
                if(!g[j][p])
                    best[i][j] = (best[i-1][p] + best[i][j]) % mod;
    show = 0;
    for(i='a';i<='z';++i)
        show = (show + best[n][i]) % mod;
    printf("%d\n",show);
}