Cod sursa(job #3334774)

Utilizator parus_majorParus Major parus_major Data 19 ianuarie 2026 19:38:05
Problema Energii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>

using namespace std;

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

const int MAXN = 52;
const int MAXD = 102;

int N, D, K;
int h[MAXN];
long long d[MAXD][MAXN][MAXD][2];

int main()
{
    fin >> N >> D >> K;
    for (int i = 1; i <= K; ++i) {
        fin >> h[i];
    }

    d[0][0][0][0] = 1LL;
    for (int i = 1; i < D; ++i) {
        for (int j = 1; j <= N; ++j) {
            for (int h_idx = 0; h_idx <= K; ++h_idx) {
                for (int x = 0; x <= 1; ++x) {
                    int step = (h_idx && j == h[h_idx]) ? 1 : 0;
                    d[i][j][h_idx][x] = d[i - 1][j - 1][h_idx - step][x] + d[i - 1][j][h_idx - step][x] + d[i - 1][j + 1][h_idx - step][x];
                    if (x == 1 && j == N) {
                        d[i][j][h_idx][x] = d[i - 1][j - 1][h_idx - step][0] + d[i - 1][j][h_idx - step][0] + d[i - 1][j + 1][h_idx - step][0];
                    }
                }
            }
        }
    }

    fout << d[D - 1][1][K][1];

    return 0;
}