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>
#define fi first
#define se second
#define pp pop_back
#define ll long long
#define pb push_back
#define ld long double
#define debug cout << "OK\n";
#define all(x) x.begin(), x.end()
#define mp make_pair
using namespace std;
const ll N = 1e6;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ll pe = mod2;
const ll pe2 = 570210983;
const ld eps = 1e-6;
/*
Rucode: jaqVYNrpMj
JUDGE_ID: 295965SY
dl:160532
*/
void data() {
#ifdef NURS
freopen("main.in", "r", stdin);
freopen("main.out", "w", stdout);
#endif
}
int n, l, cur;
int a[N];
int dp[2][15][20000][101];
vector<int> g[20];
vector<int> g2[20000];
main()
{
data();
ios_base::sync_with_stdio(0),
cin.tie(0),cout.tie(0);
cin >> n >> l;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
//optim
for (int j = 0; j < (1 << n); j++)
{
g[__builtin_popcount(j)].pb(j);
for (int i = 0; i < n; i ++)
{
if ((j & (1 << i)))
{
}
else
{
g2[j].pb(i);
}
}
}
//endoptim
for (int i = 0; i < g[1].size(); i++)
{
int k = g[1][i], bit = 0;
for (int j = 0; j < 16; j++)
{
if (k >> j & 1)
bit = j;
}
dp[0][bit][k][0] = 1;
}
//cout << g2[0][0] << '\n';
for (int i = 2; i <= n; i++)
{
for (int j = 0; j < g[i - 1].size(); j++)
{
int mask = g[i - 1][j];
for (int k = 0; k < n; k++)
{
for (int sum = 0; sum <= l; sum++)
{
if (dp[cur][k][mask][sum] > 0)
{
// cout << cur << " " << k << " " << mask << " " << sum << '\n';
for (int ind = 0; ind < g2[mask].size(); ind++)
{
int nwbit = g2[mask][ind];
// cout << nwbit << '\n';
dp[cur ^ 1][nwbit][(mask ^ (1 << nwbit))][sum + abs(a[k + 1] - a[nwbit + 1])] += dp[cur][k][mask][sum];
dp[cur ^ 1][nwbit][(mask ^ (1 << nwbit))][sum + abs(a[k + 1] - a[nwbit + 1])] %= mod;
// return 0;
}
dp[cur][k][mask][sum] = 0;
// debug;
// return 0;
}
}
}
}
cur ^= 1;
}
ll ans = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j <= l; j++)
{
ans += dp[cur][i][(1 << n) - 1][j];
ans %= mod;
}
}
cout << ans;
}
/*
6 4 2
2 9 2 3 8 5
*/
Compilation message (stderr)
skyscraper.cpp:39:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
39 | main()
| ^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:65:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for (int i = 0; i < g[1].size(); i++)
| ~~^~~~~~~~~~~~~
skyscraper.cpp:78:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for (int j = 0; j < g[i - 1].size(); j++)
| ~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:89:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for (int ind = 0; ind < g2[mask].size(); ind++)
| ~~~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |