제출 #772189

#제출 시각아이디문제언어결과실행 시간메모리
772189ttamxSkyscraper (JOI16_skyscraper)C++14
100 / 100
178 ms105392 KiB
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

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

int n,l;
int a[N];
ll dp[N][N][M][4];
ll ans;

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n >> l;
    for(int i=1;i<=n;i++)cin >> a[i];
    if(n==1)cout << 1,exit(0);
    sort(a+1,a+n+1);
    dp[1][1][0][0]=1;
    dp[1][1][0][1]=2;
    for(int i=2;i<=n;i++){
        for(int j=1;j<i;j++){
            for(int k=0;k<=l;k++){
                for(int e=0;e<3;e++){
                    int res=k+(a[i]-a[i-1])*(2*j-e);
                    if(res>l)continue;
                    dp[i][j-1][res][e]+=dp[i-1][j][k][e]*(j-1)%mod;
                    dp[i][j-1][res][e]%=mod;
                    dp[i][j][res][e]+=dp[i-1][j][k][e]*(2*j-e)%mod;
                    dp[i][j][res][e]%=mod;
                    dp[i][j+1][res][e]+=dp[i-1][j][k][e]*(j+1-e)%mod;
                    dp[i][j+1][res][e]%=mod;
                    dp[i][j][res][e+1]+=dp[i-1][j][k][e]*(2-e)%mod;
                    dp[i][j][res][e+1]%=mod;
                    dp[i][j+1][res][e+1]+=dp[i-1][j][k][e]*(2-e)%mod;
                    dp[i][j+1][res][e+1]%=mod;
                }
            }
        }
    }
    for(int i=0;i<=l;i++){
        ans+=dp[n][1][i][2];
        ans%=mod;
    }
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...