Cod sursa(job #2178679)

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

using namespace std;

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


int main(){

    cin >> N >> M >> X;

    bool u = 1;
    DP[!u][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][k] = DP[!u][k - i*j] + DP[!u][k] + DP[!u][k + i*j], DP[u][k] = DP[u][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][X] % 10000;
    //cout << DP[u][X];

    return 0;
}