Cod sursa(job #1688284)

Utilizator hunix94Karaman Hunor hunix94 Data 13 aprilie 2016 13:15:57
Problema Diamant Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;

int n, m, x;

int main() {
    ifstream input("diamant.in");
    input >> n >> m >> x;

    int ossz = n*(n + 1) / 2 * m*(m + 1) / 2;

    int pozitiv[ossz*2 + 1];
    int alt[ossz*2 + 1];

    for (int i = 0; i <= (ossz*2 + 1); i++) {
        pozitiv[i] = 0;
        alt[i] = 0;
    }

    pozitiv[0] = 1;

    int end = 1;

    for (int y = 1; y <= n; y++) {
        for (int x = 1; x <= m; x++) {

            int ertek = x*y;
            end += ertek;

            for (int i = 0; i <= end; i++) {
                alt[i] = pozitiv[i];
            }

            for (int i = 0; i <= end; i++) {
                int a = abs(i - ertek);
                alt[i] = (pozitiv[i] + pozitiv[i + ertek] + pozitiv[a])%10000;
            }

            for (int i = 0; i <= end; i++) {
                pozitiv[i] = alt[i];
            }

        }
    }

    int a = abs(x);
    ofstream output ("diamant.out");
    output << pozitiv[a]%10000 << '\n';
    output.close();

    return 0;
}