제출 #971949

#제출 시각아이디문제언어결과실행 시간메모리
97194912345678Skyscraper (JOI16_skyscraper)C++17
15 / 100
9 ms31248 KiB
#include <bits/stdc++.h>

using namespace std;

const int nx=105, mx=1005, mod=1e9+7;

#define ll long long

ll n, m, h[nx], dp[nx][nx][mx][3], res, c;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>m;
    for (int i=1; i<=n; i++) cin>>h[i];
    sort(h+1, h+n+1);
    dp[0][0][0][0]=1;
    for (int i=1; i<n; i++)
    {
        for (int j=1; j<=i; j++)
        {
            for (int k=0; k<=m; k++)
            {
                for (int l=0; l<3; l++)
                {
                    ll x=(h[i+1]-h[i])*(2*j-l);
                    if (k<x) continue;
                    dp[i][j][k][l]=dp[i-1][j-1][k-x][l];
                    if (l>0) dp[i][j][k][l]=(dp[i][j][k][l]+dp[i-1][j-1][k-x][l-1]*(3-l))%mod;
                    dp[i][j][k][l]=(dp[i][j][k][l]+dp[i-1][j][k-x][l]*(2*j-l))%mod;
                    if (l>0) dp[i][j][k][l]=(dp[i][j][k][l]+dp[i-1][j][k-x][l-1]*(3-l)*(j-(l-1)))%mod;
                    if (l==0) dp[i][j][k][l]=(dp[i][j][k][l]+dp[i-1][j+1][k-x][l]*(j+1)*j)%mod;
                    if (l==1) dp[i][j][k][l]=(dp[i][j][k][l]+dp[i-1][j+1][k-x][l]*j*j)%mod;
                    if (l==2) dp[i][j][k][l]=(dp[i][j][k][l]+dp[i-1][j+1][k-x][l]*j*(j-1))%mod;
                }
            }
        }
    }
    for (int i=0; i<=m; i++) res=(res+dp[n-1][2][i][2]+dp[n-1][1][i][1])%mod;
    cout<<res;
}

/*
4 2
1 2 3 4
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...