Cod sursa(job #887640)

Utilizator arrayAnghel Mihai array Data 23 februarie 2013 22:44:00
Problema Diamant Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

#define MOD 10000
#define AA 500
inline int good(int number) { return number % MOD; }
inline int abs(int number) { return (number < 0 ? -number : number); }
ifstream fin("diamant.in");
ofstream fout("diamant.out");
int N, M, SMAX, X, step(1);
int dp[200000][2];

int main() {

	fin >> N >> M >> X;
	for (int i = 1; i <= N; i++)
		for (int j = 1; j <= M; j++)
			SMAX = SMAX + i * j;

	dp[0 + SMAX + AA][0] = 1;
	for (int i = 1; i <= N; i++)
		for (int j = 1; j <= M; j++, step++) {
			for (int k = -SMAX; k <= SMAX; k++) {
				dp[k + SMAX + AA][step & 1] = dp[k + SMAX + AA][!(step & 1)];
				dp[k + SMAX + AA][step & 1] += dp[k - i * j + SMAX + AA][!(step & 1)];
				dp[k + SMAX + AA][step & 1] += dp[k + i * j + SMAX + AA][!(step & 1)];
				dp[k + SMAX + AA][step & 1] = good(dp[k + SMAX + AA][step & 1]);
			}
		}

	fout << (abs(X) <= abs(SMAX) ? dp[X + SMAX + AA][!(step & 1)] : 0) << '\n';
	fout.close();
	return 0;

}