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;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define repi(i,x,y) for(int i = x; i >= y; --i)
#define ci(x) int x; cin>> x
#define TC(t) ci(t); while(t--)
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define cii(x, y) ci(x); ci(y)
#define ciii(x, y, z) ci(x); ci(y); ci(z)
#define mp make_pair
//#define int long long
typedef long long ll;
typedef vector<int> vi;
const int N = 8e2 + 5;
const int NN = 16 + 15;
const int mod = 1e9+7;
const int mod1 = 1e9 + 9;
const int pi = 31;
const ll inf = 1e15 + 6;
const int block = 500;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
void readfile(){
#ifdef ONLINE_JUDGE
#else
freopen("text.inp", "r", stdin);
#endif // ONLINE_JUDGE
// freopen("text.inp", "r", stdin);
// freopen("template.out", "w", stdout);
}
int n, L;
int a[N];
void inp(){
cin >> n >> L;
for(int i = 1; i <= n; ++i) cin >> a[i];
}
int add(int x, int y){
x += y;
while(x < 0) x += mod;
while(x >= mod) x -= mod;
return x;
}
int mul(int x, int y){
return (x * 1LL * y) % mod;
}
int f[(1<<14)][14][105];
void sub2(){
for(int i = 0; i < n; ++i)
f[(1<<i)][i][0] = 1;
for(int i = 0; i < (1<<n); ++i){
for(int j = 0; j < n; ++j){
if(!((i>>j)&1)) continue;
for(int k = 0; k < n; ++k){
if(!((i>>k)&1)) continue;
if(k==j) continue;
for(int w = 0; w <= L; ++w)
if(w + abs(a[j+1] - a[k+1]) <= L)
f[i][j][w + abs(a[j+1] - a[k+1])] = add(f[i][j][w + abs(a[j+1] - a[k+1])], f[i^(1<<j)][k][w]);
}
}
}
int res = 0;
for(int w = 0; w <= L; ++w)
for(int i = 0; i < n; ++i)
res = add(res, f[(1<<n)-1][i][w]);
cout << res;
}
void process(){
if(n <= 14) sub2();
}
int main() {
//readfile();
ios_base::sync_with_stdio(0);
cin.tie(0);
inp();
process();
return 0;
}
Compilation message (stderr)
skyscraper.cpp: In function 'void readfile()':
skyscraper.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | freopen("text.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |