Cod sursa(job #2502887)

Utilizator Mihai145Oprea Mihai Adrian Mihai145 Data 1 decembrie 2019 19:20:25
Problema Diamant Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.02 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 + MAX_S; value <= smax + MAX_S; value++)
        {
            dp[value][currentCol] = dp[value - el[step]][!currentCol];
            dp[value][currentCol] += dp[value][!currentCol];
            dp[value][currentCol] += dp[value + el[step]][!currentCol];
            dp[value][currentCol] %= 10000;
        }
    }

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

    return 0;
}