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 double ld;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll MOD=1e9+7;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, l;
cin >> n >> l;
ll dp[1<<n][n][l+1], T[n];
rep(i, 1<<n) rep(j, n) rep(k, l+1) dp[i][j][k]=0;
rep(i, n) cin >> T[i];
rep(i, n) dp[1<<i][i][0]=1;
rep(i, 1<<n) rep(j, n) if(i&(1<<j)) {
rep(k, n) if(j!=k && (i&(1<<k))) {
for(int a=abs(T[j]-T[k]); a<=l; ++a) {
dp[i][j][a]=(dp[i][j][a]+dp[i-(1<<j)][k][a-abs(T[j]-T[k])])%MOD;
}
}
}
ll ans=0;
rep(i, n) rep(j, l+1) ans=(ans+dp[(1<<n)-1][i][j])%MOD;
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... |