Cod sursa(job #467221)

Utilizator antoanelaAntoanela Siminiuc antoanela Data 28 iunie 2010 13:09:44
Problema Pod Scor 0
Compilator cpp Status done
Runda Stelele Informaticii 2010, clasele X-XII, Ziua 2 Marime 0.83 kb
#include <cstdio>
#define X 9901

int v[1010], a[1000010], n, k, m;

int main()
{
    freopen("pod.in","r",stdin);
    freopen("pod.out","w",stdout);
    scanf("%d %d %d",&n,&m,&k);
    int i, p, c, j, t;
    p=1;
    for (i=1; i<=m; i++) scanf ("%d",&v[i]);
    if (!n)
    {
        printf("1\n");
        return 0;
    }
    if (k==1)
    {
        if (!m) printf("1\n"); else printf("0\n");
        return 0;
    }
    if (k==1) k=0;
    c=1;
    p=1;
    a[0]=1;
    t=0;
    for (i=1; i<=n; i++)
    {
        if (i==v[c]) c++; else
        {
            a[p]=a[p-1]%X;
            if (p>=k) a[p]=(a[p]+a[p-k])%X;
        }
        p++;
        if (p==23)
        {
            t=1;
            for (j=1; j<=22; j++) a[j]=a[j+1];
            p=22;
        }
    }
    printf("%d\n",a[p-1]);

}