답안 #527593

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527593 2022-02-17T17:45:37 Z Monarchuwu Skyscraper (JOI16_skyscraper) C++17
15 / 100
1 ms 716 KB
/**
 *  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
**/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 584 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 704 KB Output is correct
7 Correct 1 ms 572 KB Output is correct
8 Correct 1 ms 704 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -