Cod sursa(job #8743)

Utilizator cristi8Constantin-Cristian Balas cristi8 Data 25 ianuarie 2007 15:10:04
Problema 1-sir Scor 100
Compilator c Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <stdio.h>
#define SMAX (64*257+1)
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MOD 194767
#define col(j) ((j)%2)

int n, S;
int a[SMAX][2];

int main()
{	
  int i, j;
  freopen("1-sir.in", "r", stdin);
  freopen("1-sir.out", "w", stdout);
  scanf("%d%d", &n, &S);
  if(S < 0)
    S = -S;
  if((n/2)%2 != S%2) {
    printf("0\n");
    return 0;
  }
  S = ((n*(n-1))/2 - S) / 2;
  if(S <= 0) {
    printf("%d\n", S < 0 ? 0 : 1);
    return 0;
  }
  n--;

  for(j = MIN(n, S-1); j > 0; j--)
  {
    a[j][col(j)] = 1;
    if(j + 1 <= n)
      a[j+1][col(j+1)] = 1;
    for(i = j+1; i <= S; i++)
      a[i][col(j)] = (a[i][col(j+1)] + a[i-j][col(j+1)]) % MOD;
  }

  printf("%d\n", a[S][col(1)]);
  return 0;
}