Pagini recente » Cod sursa (job #3223206) | Cod sursa (job #3224192) | Cod sursa (job #2066979) | Monitorul de evaluare | Cod sursa (job #7543)
Cod sursa(job #7543)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define ABS(a) ( (a) < 0 ? -(a) : (a) )
#define NMAX 32560
#define MOD 194767
int N, S, A[2*NMAX + 1], Ap[2*NMAX + 1];
int MaxV;
#define A (A + NMAX)
#define Ap (Ap + NMAX)
int i, sp;
int main()
{
freopen("1-sir.in" , "r", stdin);
freopen("1-sir.out", "w", stdout);
scanf("%d %d", &N, &S);
MaxV = N*(N-1)/2;
if (ABS(S) > MaxV) { printf("0\n"); return 0; }
Ap[0] = 1;
for (i = 1; i < N; i++)
{
for (sp = -MaxV; sp <= MaxV; sp++)
{
A[sp] = (Ap[sp - i] + Ap[sp + i]) % MOD;
}
for (sp = -MaxV; sp <= MaxV; sp++) Ap[sp] = A[sp];
}
printf("%d\n", Ap[S]);
return 0;
}