Cod sursa(job #2178706)

Utilizator cyber_ghSoltan Gheorghe cyber_gh Data 19 martie 2018 17:53:58
Problema Diamant Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <bits/stdc++.h>

using namespace std;

int DP[2][200110];
ifstream fin("diamant.in");
ofstream fout("diamant.out");
int N,M,X;
const int lim = 60000;

inline int eval(int val){
    return lim - val;
}

int main(){

    fin >> N >> M >> X;

    bool u = 1;
    DP[!u][eval(0)] = 1;
    if (abs(X) > lim) {
        fout << 0;
        return 0;
    }
    for (int i = 1; i <= N;i++){
        for (int j = 1; j <= M;j++,u = !u){
            for (int k = lim; k >= -lim;k--) DP[u][eval(k)] = DP[!u][eval(k - i*j)] + DP[!u][eval(k)] + DP[!u][eval(k + i*j)], DP[u][eval(k)] = DP[u][eval(k)] % 10000;
//            for (int k = lim; k >= -lim;k--) cout <<k<< "-"<< DP[!u][k] << " ";
//            cout << endl;
//            for (int k = lim; k >= -lim;k--) cout <<k<< "-"<< DP[u][k] << " ";
//            cout << endl;
//            cout << endl;
        }
    }

    fout << DP[!u][eval(X)] % 10000;
    //cout << DP[u][X];

    return 0;
}