# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
372809 | MiricaMatei | Skyscraper (JOI16_skyscraper) | C++14 | 173 ms | 70124 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 MAXN = 105;
const int MAXL = 1005;
const int MOD = 1e9 + 7;
int a[MAXN];
int dp[MAXN][MAXN][MAXL][5];
int main() {
//freopen("date.in", "r", stdin);
//freopen("date.out", "w", stdout);
int n, l;
scanf("%d%d", &n, &l);
for (int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
sort(a + 1, a + n + 1);
reverse(a + 1, a + n + 1);
dp[1][0][0][0] = 1;
dp[1][0][0][1] = 2;
dp[1][0][0][2] = 1;
for (int i = 1; i < n; ++i) {
int dif = a[i] - a[i + 1];
for (int j = 0; j <= i + 1; ++j) {
for (int s = 0; s <= l; ++s) {
for (int e = 0; e <= 2; ++e) {
int ns = s + dif * (2 * j + 2 - e);
if (ns > l)
continue;
if (j - 1 >= 0)
dp[i + 1][j - 1][ns][e] = (dp[i + 1][j - 1][ns][e] + 1LL * j * dp[i][j][s][e]) % MOD;
dp[i + 1][j][ns][e] = (dp[i + 1][j][ns][e] + 1LL * (2 * j + 2 - e) * dp[i][j][s][e]) % MOD;
dp[i + 1][j + 1][ns][e] = (dp[i + 1][j + 1][ns][e] + 1LL * (j + 2 - e) * dp[i][j][s][e]) % MOD;
if (e + 1 <= 2)
dp[i + 1][j][ns][e + 1] = (dp[i + 1][j][ns][e + 1] + 1LL * (2 - e) * dp[i][j][s][e]) % MOD;
if (e + 1 <= 2)
dp[i + 1][j + 1][ns][e + 1] = (dp[i + 1][j + 1][ns][e + 1] + 1LL * (2 - e) * dp[i][j][s][e]) % MOD;
}
}
}
}
int ans = 0;
for (int i = 0; i <= l; ++i)
ans = (ans + dp[n][0][i][2]) % MOD;
printf("%d\n", ans);
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... |