Cod sursa(job #2532632)

Utilizator IoanaDraganescuIoana Draganescu IoanaDraganescu Data 28 ianuarie 2020 01:42:03
Problema Diamant Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.2 kb
#include <iostream>
#include <fstream>

using namespace std;

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

const int Smax = 44100, mod = 10000;

int n, m, x;
int dp[2][2 * Smax + 5];
bool ok;

void Read(){
    fin >> n >> m >> x;
}

void Solve(){
    ok = 1;
    if (x < -Smax || x > Smax){
        ok = 0;
        return;
    }
    dp[1][Smax] = 1;
    dp[1][Smax + 1] = 1;
    dp[1][Smax - 1] = 1;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            if (i != 1 || j != 1){
                int aux = (i - 1) * m + j;
                for (int s = 2 * Smax; s >= 0; s--){
                    int sum = 0;
                    sum += dp[(aux - 1) % 2][s];
                    if (s - i * j >= 0)
                        sum += dp[(aux - 1) % 2][s - i * j];
                    if (s + i * j <= 2 * Smax)
                        sum += dp[(aux - 1) % 2][s + i * j];
                    dp[aux % 2][s] = sum % mod;
                }
            }
}

void Print(){
    if (!ok)
        fout << 0 << '\n';
    else
        fout << dp[m * n % 2][x + Smax] << '\n';
}

int main(){
    Read();
    Solve();
    Print();
    return 0;
}