Cod sursa(job #467076)

Utilizator PavelRazvanPavel Razvan PavelRazvan Data 28 iunie 2010 11:20:06
Problema Pod Scor 15
Compilator cpp Status done
Runda Stelele Informaticii 2010, clasele X-XII, Ziua 2 Marime 0.95 kb
#include<algorithm>
using namespace std;
#define DIM 1005
#define DIM2 30
#define MOD 9901

int n,m,k,a[DIM],b[25];


inline int mod (int x)
{
    while(x>=MOD)
        x-=MOD;
    return x;
}

char buff[DIM2];
int poz;
inline void pars (int &nr)
{
    nr=0;
    while(buff[poz]<'0' || buff[poz]>'9')
        if(++poz==DIM2)
            fread(buff,1,DIM2,stdin),poz=0;
    while(buff[poz]>='0' && buff[poz]<='9')
    {
        nr=nr*10+buff[poz]-'0';
        if(++poz==DIM2)
            fread(buff,1,DIM2,stdin),poz=0;
    }
}
int main ()
{
    freopen("pod.in","r",stdin);
    freopen("pod.out","w",stdout);
    int i;
    pars(n);
    pars(m);
    pars(k);
    for(i=1;i<=m;++i)
        pars(a[i]);
    sort(1+a,1+a+m);
    b[0]=1;
    for(i=1;i<=n;++i)
        if(!binary_search(1+a,1+a+m,i))
            b[i%k]=mod(b[(i-1)%k]+b[(i-k)%k]);
        else
            b[i%k]=0;
    printf("%d",mod(b[n%k]));
    return 0;
}