This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define bit(mask, i) ((mask >> (i)) & 1)
const int N = 1e2 + 5;
const int mod = 1e9 + 7;
void add(int &a, int b) {
a += b;
if(a >= mod) a -= mod;
if(a < 0) a += mod;
}
int n, L, a[N];
int dp[1 << 14][14][1005];
void solve() {
cin >> n >> L;
for(int i = 0; i < n; ++i) {
cin >> a[i];
dp[1 << i][i][0] = 1;
}
for(int mask = 1; mask < (1 << n); ++mask) {
for(int i = 0; i < n; ++i) if(bit(mask, i)) {
for(int j = 0; j < n; ++j) if(!bit(mask, j)) {
for(int diff = 0; diff + abs(a[i] - a[j]) <= L; ++diff) {
add(dp[mask | (1 << j)][j][diff + abs(a[i] - a[j])], dp[mask][i][diff]);
}
}
}
}
int ans = 0;
for(int i = 0; i < n; ++i) {
for(int diff = 0; diff <= L; ++diff) add(ans, dp[(1 << n) - 1][i][diff]);
}
cout << ans << '\n';
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int test = 1;
// cin >> test;
while(test--) solve();
return 0;
}
// https://oj.uz/problem/view/JOI16_skyscraper
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |