Pagini recente » Cod sursa (job #1439178) | Cod sursa (job #1693259) | Cod sursa (job #640603) | Cod sursa (job #756616) | Cod sursa (job #3334774)
#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;
}