//Author RufatM
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<string> vs;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ff first
#define ss second
#define all(x) begin(x),end(x)
#define rall(x) rbegin(x),rend(x)
#define mt19937_64 mt_rand(chrono::steady_clock::now().time_since_epoch().count())
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
const int MOD=1000000007;
const int INF=1000000007;
const ll LINF=4e18;
const int MAXN=2005;
signed main(){
fastio;
#ifndef ONLINE_JUDGE
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
#endif
int t=1;
//cin >> t;
while(t--){
int n,l;
cin >> n >> l;
if(n==1){
cout << 1;
return 0;
}
vi a(n+2);
for(int i=1;i<=n;i++){
cin >> a[i];
}
sort(a.begin()+1,a.begin()+n+1);
a[n+1] = 10000;
vector<vector<vector<vector<ll>>>> dp(n+2,vector<vector<vector<ll>>>(n+2,vector<vector<ll>>(l+2,vll(3,0))));
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<=l;k++){
for(int m=0;m<=2;m++){
int cost = (2*j-m)*(a[i+1]-a[i]);
if(cost>k or i+j+1-m>n){
continue;
}
dp[i][j][k][m] += dp[i-1][j-1][k-cost][m];
if(m>0){
dp[i][j][k][m] += (3-m)*dp[i-1][j-1][k-cost][m-1];
}
dp[i][j][k][m] += (2*j-m)*dp[i-1][j][k-cost][m];
if(m==1){
dp[i][j][k][m] += 2LL*j*dp[i-1][j][k-cost][m-1];
}
else if(m==2){
if(i==n){
dp[i][j][k][m] += dp[i-1][j][k-cost][m-1];
}
else{
if(j>1){
dp[i][j][k][m] += (j-1)*dp[i-1][j][k-cost][m-1];
}
}
}
if(m==2){
if(i==n){
dp[i][j][k][m] += dp[i-1][j+1][k-cost][m];
}
else{
dp[i][j][k][m] += 1LL*j*(j-1)*dp[i-1][j+1][k-cost][m];
}
}
else if(m==1){
dp[i][j][k][m] += 1LL*j*j*dp[i-1][j+1][k-cost][m];
}
else{
dp[i][j][k][m] += 1LL*j*(j+1)*dp[i-1][j+1][k-cost][m];
}
dp[i][j][k][m] %= MOD;
}
}
}
}
ll ans = 0;
for(int k=0;k<=l;k++){
ans = (ans + dp[n][1][k][2])%MOD;
}
cout << ans << endl;
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |