其他分享
首页 > 其他分享> > [LOJ#2743][DP]「JOI Open 2016」摩天大楼

[LOJ#2743][DP]「JOI Open 2016」摩天大楼

作者:互联网

Code

#include <bits/stdc++.h>
#define vf(ii, jj) f[op ^ 1][ii][w][jj]

template <class T>
inline void read(T &res)
{
    res = 0; bool bo = 0; char c;
    while (((c = getchar()) < '0' || c > '9') && c != '-');
    if (c == '-') bo = 1; else res = c - 48;
    while ((c = getchar()) >= '0' && c <= '9')
        res = (res << 3) + (res << 1) + (c - 48);
    if (bo) res = ~res + 1;
}

const int N = 105, M = 1005, rqy = 1e9 + 7;

int n, l, a[N], f[2][N][M][3], ans;

int main()
{
    read(n); read(l);
    for (int i = 1; i <= n; i++) read(a[i]);
    if (n == 1) return puts("1"), 0;
    std::sort(a + 1, a + n + 1);
    f[0][0][0][0] = 1; a[0] = a[1];
    for (int i = 0; i < n; i++)
    {
        int op = i & 1;
        for (int j = 0; j <= i + 1; j++)
            for (int k = 0; k <= l; k++)
                f[op ^ 1][j][k][0] = f[op ^ 1][j][k][1] = f[op ^ 1][j][k][2] = 0;
        for (int j = 0; j <= i; j++)
            for (int k = 0; k <= l; k++)
                for (int h = 0; h < 3; h++)
                {
                    if (!f[op][j][k][h]) continue;
                    int w = k + (a[i + 1] - a[i]) * (j * 2 - h), cf = f[op][j][k][h];
                    if (w > l) continue;
                    vf(j + 1, h) = (1ll * (j + 1 - h) * cf + vf(j + 1, h)) % rqy;
                    if (j) vf(j - 1, h) = (1ll * (j - 1) * cf + vf(j - 1, h)) % rqy;
                    vf(j, h) = (1ll * (j * 2 - h) * cf + vf(j, h)) % rqy;
                    if (h < 2)
                    {
                        if (j) vf(j, h + 1) = (1ll * (2 - h) * cf + vf(j, h + 1)) % rqy;
                        vf(j + 1, h + 1) = (1ll * (2 - h) * cf + vf(j + 1, h + 1)) % rqy;
                    }
                }
    }
    for (int i = 0; i <= l; i++) ans = (ans + f[n & 1][1][i][2]) % rqy;
    return std::cout << ans << std::endl, 0;
}

标签:边界,vf,LOJ,cf,times,2743,JOI,1ll,rqy
来源: https://www.cnblogs.com/xyz32768/p/11973068.html