Cod sursa(job #176537)

Utilizator plastikDan George Filimon plastik Data 11 aprilie 2008 13:45:03
Problema Diamant Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
// Diamant, Infoarena/ONI 2006
// http://infoarena.ro/problema/diamant

#include <cstdio>
#include <cstring>

const int XMAX = 45000;
const int MOD = 10000;

int n, m, x;
int Prev[2 * XMAX], Curr[2 * XMAX];

int main() {

	freopen("diamant.in", "r", stdin);
	freopen("diamant.out", "w", stdout);

	scanf("%d %d %d", &m, &n, &x);

	if (x >= XMAX || x <= -XMAX) {
		printf("0\n");
		return 0;
	}

	int s, c, i, j, xmax = 0;

	Prev[XMAX] = 1;
	for (i = 1; i <= m; ++ i)
		for (j = 1; j <= n; ++ j) {
			xmax += i * j;
			for (c = XMAX - xmax; c <= XMAX + xmax; ++ c)
				Curr[c] = (Prev[c] + Prev[c - i * j] + Prev[c + i * j]) % MOD;
			memmove(Prev, Curr, sizeof(Curr));
		}

	printf("%d\n", Curr[XMAX + x]);

	return 0;
}