Cod sursa(job #2502886)

Utilizator Mihai145Oprea Mihai Adrian Mihai145 Data 1 decembrie 2019 19:13:52
Problema Diamant Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.06 kb
#include <fstream>
#include <vector>

using namespace std;

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

const int MAX_S = 44500;

int N, M, X;
vector <int> el;

int dp[2 * MAX_S + 5][2];

int main()
{
    fin >> N >> M >> X;

    int smax = 0;
    for(int i = 1; i <= N; i++)
        for(int j = 1; j <= M; j++)
        {
            el.push_back(i * j);
            smax += i * j;
        }

    if(X < -smax || smax < X)
    {
        fout << 0 << '\n';
        return 0;
    }

    int currentCol = 0;

    dp[0 + MAX_S][0] = 1;

    for(int step = 0; step < N * M; step++)
    {
        currentCol = !currentCol;

        for(int value = -smax; value <= smax; value++)
        {
            dp[value + MAX_S][currentCol] = dp[value - el[step] + MAX_S][!currentCol];
            dp[value + MAX_S][currentCol] += dp[value + MAX_S][!currentCol];
            dp[value + MAX_S][currentCol] += dp[value + el[step] + MAX_S][!currentCol];
            dp[value + MAX_S][currentCol] %= 10000;
        }
    }

    fout << dp[X + MAX_S][currentCol] << '\n';

    return 0;
}