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;
typedef long long ll;
ll dp[14][101][1<<14];
int n, l;
int ar[100];
ll mod = 1000000007LL;
ll go(int mask, int rem, int last){
if(rem<0){
return 0LL;
}
if(mask==0){
return 1LL;
}
if(dp[last][rem][mask]!=-1LL){
return dp[last][rem][mask];
}
ll ret = 0LL;
for(int i = 0; i<n; i++){
if((mask&(1<<i))!=0){
ret += go(mask-(1<<i), rem-abs(ar[i]-ar[last]),i);
}
}
ret %= mod;
dp[last][rem][mask] = ret;
return ret;
}
int main(){
cin >> n >> l;
for(int i = 0; i<n; i++){
cin >> ar[i];
}
int maxi = (1<<n);
for(int i = 0; i<n; i++){
for(int j = 0; j<=l; j++){
for(int k = 0; k<maxi; k++){
dp[i][j][k] = -1LL;
}
}
}
ll ret = 0;
for(int i = 0; i<n; i++){
ret += go(maxi-1-(1<<i), l, i);
}
ret %= mod;
cout << ret << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |