Cod sursa(job #2178656)

Utilizator cyber_ghSoltan Gheorghe cyber_gh Data 19 martie 2018 17:23:51
Problema Diamant Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 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 = 10;


int main(){

    cin >> N >> M >> X;

    bool u = 1;
    DP[!u][0] = 1;
    DP[u][0] = 1;

    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] %= 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];
    //cout << DP[u][X];

    return 0;
}