# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
132780 | Just_Solve_The_Problem | Skyscraper (JOI16_skyscraper) | C++11 | 2062 ms | 97532 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;
const int N = (int)1e2 + 7;
const int mod = (int)1e9 + 7;
int add(int a, int b) {
return (a + b) % mod;
}
int mul(int a, int b) {
return (a * 1LL * b) % mod;
}
int n, l;
int a[N];
int dp[1 << 14][101][15];
int go(int mask, int lst, int sum) {
if (mask == 0) return 1;
int &res = dp[mask][sum][lst];
if (res != -1) return res;
res = 0;
for (int i = 0; i < n; i++) {
if ((mask >> i) & 1 ^ 1) continue;
int cost = abs(a[lst] - a[i]);
if (lst == n) cost = 0;
if (sum + cost <= l)
res += go(mask ^ (1 << i), i, sum + cost);
}
return res;
}
main() {
memset(dp, -1, sizeof dp);
scanf("%d %d", &n, &l);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
sort(a, a + n);
int ans = 0;
do {
int sum = 0;
for (int i = 1; i < n; i++) {
sum += abs(a[i] - a[i - 1]);
}
ans += (sum <= l);
} while (next_permutation(a, a + n));
printf("%d", ans);
}
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... |