Cod sursa(job #1365585)

Utilizator assa98Andrei Stanciu assa98 Data 28 februarie 2015 13:25:10
Problema Diamant Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.18 kb
#include <fstream>
#include <algorithm>
using namespace std;

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

const int MAX_N = 410;
const int MAX_S = 100000;
const int MOD = 10000;

int d[2][2 * MAX_S + 100];
int v[MAX_N];

int main() {
    int n, m, s;
    fin >> n >> m >> s;
    int ms = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            v[++v[0]] = i * j;
            ms += v[v[0]];
        }
    }

    if(s > ms || s < -ms) {
        fout << 0;
        return 0;
    }

    d[0][MAX_S] = 1;

    int smin = MAX_S;
    int smax = MAX_S;
    for(int i = 1; i <= n * m; i++) {
        for(int j = smin; j <= smax; j++) {
            d[(i & 1)][j] = d[1 - (1 & i)][j];
        }
        for(int j = smin; j <= smax; j++) {
            d[(i & 1)][j + v[i]] += d[1 - (i & 1)][j];
            d[(i & 1)][j + v[i]] %= MOD;
            d[(i & 1)][j - v[i]] += d[1 - (i & 1)][j];
            d[(i & 1)][j - v[i]] %= MOD;
        }
        smin -= v[i];
        smax += v[i];

        /*for(int j = smin; j <= smax; j++) {
            fout << d[i & 1][j] << ' ';
        }
        fout << '\n';*/
    }

    fout << d[((n * m) & 1)][MAX_S + s];

    return 0;

}