Cod sursa(job #19037)

Utilizator alextheroTandrau Alexandru alexthero Data 18 februarie 2007 18:12:01
Problema 1-sir Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <cstdio>

#define nmax 300
#define smax 32645
#define modulo 194767

int n,s;
int first[smax],second[smax];

inline int absol(int x) {
    if(x < 0) return -x;
    else return x;
}

int main() {
    freopen("1-sir.in","r",stdin);
    freopen("1-sir.out","w",stdout);

    scanf("%d %d\n",&n,&s);

    s = absol(s);
    if(s >= smax) {
        printf("0\n");
        return 0;
    }

    second[0] = 1;
    for(int i = 2; i <= n; i++) {
        for(int j = 0; j < smax; j++) first[j] = second[j];
        for(int j = 0; j < smax; j++) {
            second[j] = first[absol(j - (i - 1))] + first[j + (i - 1)];
            second[j] %= modulo;
        }
    }

    printf("%d\n",second[s]);

    return 0;
}