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 int long long
const int modulo = 1e9+7;
int DP[16384][101][14];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n,l;
cin >> n >> l;
vector<int> arr(n);
for(int&i:arr)cin>>i;
for(int bitmask=0;bitmask<(1<<n);bitmask++){
for(int currlen=0;currlen<=l;currlen++){
for(int last=0;last<n;last++){
if((bitmask&(1<<last))==0)continue;
if(bitmask==(1<<last)){DP[bitmask][currlen][last]=1;continue;}
int lastmask = bitmask^(1<<last);
for(int bit=0;bit<n;bit++){
if(lastmask&(1<<bit)){
if(abs(arr[last]-arr[bit])<=currlen)DP[bitmask][currlen][last]+=DP[lastmask][currlen-abs(arr[last]-arr[bit])][bit];
}
}
}
}
}
int ans = 0;
for(int i=0;i<n;i++){
ans+=DP[(1<<n)-1][l][i];
ans%=modulo;
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |