#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;
int n, l;
vector<int> heights;
vector<vector<vector<int>>> dp;
int doDp(int bitmask, int last, int tot) {
if (dp[bitmask][last][tot] != -1) return dp[bitmask][last][tot];
int prevBitmask = bitmask - (1 << last);
dp[bitmask][last][tot] = 0;
for (int i = 0; i < n; ++i) {
if (!((1 << i) & prevBitmask) || tot < abs(heights[i] - heights[last])) continue;
dp[bitmask][last][tot] += doDp(prevBitmask, i, tot - abs(heights[i] - heights[last]));
}
return dp[bitmask][last][tot];
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> l;
heights.resize(n);
for (int &i : heights) cin >> i;
// sort(heights.begin(), heights.end());
dp.resize((1 << n), vector<vector<int>>(n, vector<int>(l + 1, -1)));
for (int i = 0; i < n; ++i) {
for (int j = 1; j <= l; ++j) dp[(1 << i)][i][j] = 0;
dp[(1 << i)][i][0] = 1;
}
int res = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= l; ++j) {
res += doDp((1 << n) - 1, i, j);
// cout << i << ' ' << j << ' ' << doDp((1 << n) - 1, i, j) << '\n';
res %= 1'000'000'009;
}
}
cout << res << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |