Cod sursa(job #784069)

Utilizator marinMari n marin Data 4 septembrie 2012 21:42:44
Problema Diamant Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <fstream>
#include <string.h>
#define MOD 10000

#define DIM 21
using namespace std;

int V[DIM*DIM * (DIM+1)*(DIM+1)];
int W[DIM*DIM * (DIM+1)*(DIM+1)];

int *P = V + (DIM*DIM * (DIM+1)*(DIM+1))/2;
int *Q = W + (DIM*DIM * (DIM+1)*(DIM+1))/2;

int N, M, i, j, k, t, v, minim, maxim, X;

int main() {
	ifstream f("diamant.in");
	ofstream g("diamant.out");
	f>>N>>M>>X;
	P[0] = 1;
	for (i=1;i<=N;i++)
		for (j=1;j<=M;j++){
			for (k=-1;k<=1;k++) {
				v = i*j*k;
				
				for (t=minim;t<=maxim;t++)
					if (P[t]!=0) {
						Q[t+v]+=P[t];
						Q[t+v] %= MOD;
						if (t+v > maxim)
							maxim = t+v;
						if (t+v < minim)
							minim = t+v;
					}
			}
			memcpy(V, W, sizeof(V));
			memset(W, 0, sizeof(W));
		}
	g<<P[X];
	return 0;
}