Cod sursa(job #1146153)

Utilizator antonioteoZait Teodor Antonio antonioteo Data 18 martie 2014 19:16:30
Problema Diamant Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <cmath>
#include <fstream>
#include <cstring>
#include <iostream>
using namespace std;

ifstream fin("diamant.in");
ofstream fout("diamant.out");

#define MOD 10001
#define SMAX 44101

int i, j, k, x, N, M, X;
int dp[2][2 * SMAX];
int lin, col;
int cnt, lim;

int main() {
	fin >> N >> M >> X;
	lim = N * M;
	lin = 1;
	dp[0][0] = 1;
	for (i = 1; i <= lim; ++i) {
		++col;
		if (col > M) {
			col = 1; 
			++lin;
		}
		cnt ^= 1;
		memset(dp[cnt], 0, sizeof(dp[cnt]));
		for (j = 0; j < SMAX; ++j)
			dp[cnt][j] = (dp[cnt ^ 1][j] + dp[cnt ^ 1][abs(j - lin * col)] + dp[cnt ^ 1][j + lin * col]) % MOD;
	}
	if (abs(X) >= SMAX) fout << "0\n";
	else 
		fout << dp[cnt][abs(X)] << '\n';
	return 0;
}