# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
365425 | BartolM | Skyscraper (JOI16_skyscraper) | C++17 | 926 ms | 94700 KiB |
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 X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;
const int INF=0x3f3f3f3f;
const int N=14;
const int MOD=1e9+7;
int n, m;
int p[N];
int dp[(1<<14)+2][N][105];
int add(int a, int b) {
return (a+b)%MOD;
}
int rek(int mask, int pr, int br) {
if (br>m) return 0;
if (__builtin_popcount(mask)==n) return 1;
int &ret=dp[mask][pr][br];
if (ret!=-1) return ret;
ret=0;
for (int i=0; i<n; ++i) {
if (mask & (1<<i)) continue;
ret=add(ret, rek(mask | (1<<i), i, br+abs(p[i]-p[pr])));
}
return ret;
}
void load() {
scanf("%d %d", &n, &m);
for (int i=0; i<n; ++i) scanf("%d", &p[i]);
}
int main() {
load();
assert(n<=14);
memset(dp, -1, sizeof dp);
int sol=0;
for (int i=0; i<n; ++i) sol=add(sol, rek((1<<i), i, 0));
printf("%d\n", sol);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |