Cod sursa(job #863421)

Utilizator Catah15Catalin Haidau Catah15 Data 23 ianuarie 2013 19:57:09
Problema Diamant Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

#define MOD 10000
#define maxS 100000

int DP[3][2 * (maxS + 5)];


int main()
{
    freopen ("diamant.in", "r", stdin);
    freopen ("diamant.out", "w", stdout);

    int N, M, X;
    scanf ("%d %d %d", &N, &M, &X);

    DP[0][maxS] = 1;
    int t = 1;

    for (int x = 1; x <= N; ++ x)
        for (int y = 1; y <= M; ++ y)
        {
            int l = t % 2;

            for (int j = - maxS; j < maxS; ++ j)
            {
                DP[l][j + maxS] = 0;
                if (j - x * y >= - maxS) DP[l][j + maxS] += DP[!l][j - x * y + maxS];
                DP[l][j + maxS] += DP[!l][j + maxS];
                if (j + x * y <= 2 * maxS) DP[l][j + maxS] += DP[!l][j + x * y + maxS];
                DP[l][j + maxS] %= MOD;
            }

            ++ t;
        }

    printf ("%d", DP[(N * M) % 2][X + maxS]);

    return 0;
}