Cod sursa(job #112772)

Utilizator alex_mircescuAlex Mircescu alex_mircescu Data 7 decembrie 2007 15:12:54
Problema Diamant Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <stdio.h>
#include <math.h>

long n, m, i, j, h, pos, x, v[2][90010];

int main() {
	freopen("diamant.in", "r", stdin);
	freopen("diamant.out", "w", stdout);
	scanf("%ld%ld%ld", &n, &m, &x);
	v[0][45000] = 1;
	pos = 0;
	for (i = 1; i <= n; ++i) {
		for (j = 1; j <= m; ++j) {
			for (h = 0; h <= 90000; ++h) {
				if (v[pos][h] == 0) continue;
				v[!pos][h - i * j] += v[pos][h];
				v[!pos][h - i * j] %= 10000;
				v[!pos][h] += v[pos][h];
				v[!pos][h] %= 10000;
				v[!pos][h + i * j] += v[pos][h];
				v[!pos][h + i * j] %= 10000;
				v[pos][h] = 0;
			}
			pos = !pos;
		}
	}
	printf("%ld\n", v[pos][x + 45000]);
	return 0;
}