Pagini recente » Cod sursa (job #1062280) | Cod sursa (job #652540) | Cod sursa (job #2336228) | Cod sursa (job #40418) | Cod sursa (job #41880)
Cod sursa(job #41880)
#include <stdio.h>
#include <string.h>
#define INPUT "1-sir.in"
#define OUTPUT "1-sir.out"
#define MAXN 257
#define MAX 32640
#define CONST 194767
int N, S;
int rez[MAX*2 + 1], rez2[MAX*2 + 1];
// rez[i][j] = numarul de siruri cu i termeni si suma j
int main()
{
freopen(INPUT, "r", stdin);
scanf("%d %d", &N, &S);
int i, j;
rez[MAX] = 1;
for(i = 2; i <= N; ++i)
{
memset(rez2, 0, sizeof(rez2));
for(j = -MAX; j <= MAX; ++j)
{
if(j - (i-1) >= -MAX) rez2[MAX + j] = (rez2[MAX + j] + rez[MAX + j - (i-1)]) % CONST;
if(j + (i-1) <= MAX) rez2[MAX + j] = (rez2[MAX + j] + rez[MAX + j + (i-1)]) % CONST;
}
memcpy(rez, rez2, sizeof(rez2));
}
freopen(OUTPUT, "w", stdout);
printf("%d\n", rez2[S + MAX]);
return 0;
}