Cod sursa(job #448387)

Utilizator SpiderManSimoiu Robert SpiderMan Data 3 mai 2010 17:42:36
Problema Diamant Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <fstream>
using namespace std;

const char FIN[] = "diamant.in";
const char FOU[] = "diamant.out";
const int MOD = 10000;
const int MAX = 1 << 16;

int M, N, X;
int i, j, l;
int V[MAX], AUX[MAX];

int main()
{
    ifstream f(FIN);
    ofstream g(FOU);

    f >> M >> N >> X;

    int limit = N * M * (N + 1) * (M + 1) >> 2;

    if ((X = abs(X)) > limit)
        g << "0";
    else
    {
        V[0] = 1;
        for (i = 1; i <= M ; ++i)
            for (j = 1; j <= N; ++j)
            {
                for (l = 0; l <= limit; ++l)
                    AUX[l] = V[ abs( l - i * j ) ] + V[ l ] + V[ l + i * j ], AUX[l] %= MOD;

                memcpy(V , AUX , sizeof(AUX));
            }
        g << V[X] % MOD;
    }
    return 0;
}