This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* Problem: JOI16_skyscraper - Skyscraper
* Link: https://oj.uz/problem/view/JOI16_skyscraper
* Tags: DP CC
* Solution: xét chiều cao các tòa nhà chưa biết là h[i + 1]
**/
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 100 + 3, L = 1000 + 3, mod = 1e9 + 7;
int n, l;
int h[N];
#define add(a, b) (a += b) %= mod
ll dp[N][N][L][3];
int main() {
cin.tie(NULL)->sync_with_stdio(false);
cin >> n >> l;
for (int i = 1; i <= n; ++i) cin >> h[i];
sort(h + 1, h + n + 1);
dp[1][1][0][0] = 1;
dp[1][1][0][1] = 2;
for (int i = 1; i < n - 1; ++i)
for (int j = 1; j <= i; ++j)
for (int k = 0, nxtk; k <= l; ++k)
for (int x = 0; x < 3; ++x) if (dp[i][j][k][x]) {
nxtk = k + (j * 2 - x) * (h[i + 1] - h[i]);
if (nxtk > l) continue;
// tạo cc mới giữa 2 cc thường
add(dp[i + 1][j + 1][nxtk][x], dp[i][j][k][x] * (j - x + 1));
if (x < 2) // tạo cc mới dính với 1 đầu permu
add(dp[i + 1][j + 1][nxtk][x + 1], dp[i][j][k][x] * (2 - x));
// dán vào 1 cc
add(dp[i + 1][j][nxtk][x], dp[i][j][k][x] * (2 * j - x));
if (j != x) { // nối 2 cc thường (j != x để không nối 2 đầu permu)
add(dp[i + 1][j - 1][nxtk][x], dp[i][j][k][x] * (j - 1));
if (x < 2) // tạo cc mới nối 1 đầu permu với 1 cc
add(dp[i + 1][j][nxtk][x + 1], dp[i][j][k][x] * (2 - x));
}
}
ll sum(0);
for (int k = 0, nxtk; k <= l; ++k) {
nxtk = k + h[n] - h[n - 1];
if (nxtk <= l)
sum += dp[n - 1][1][k][1];
nxtk += h[n] - h[n - 1];
if (nxtk <= l)
sum += dp[n - 1][2][k][2];
}
cout << sum % mod << '\n';
}
/** /\_/\
* (= ._.)
* / >0 \>1
**/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |