This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
const int mod = 1e9+7;
const int mxN = 105;
const int mxL = 1005;
const int mxA = 1005;
int N, L, A[mxN];
int res[mxN][mxN][mxL][3];
// processing ith element, j connected component, k cost, l ends open
int dp(int i, int j, int k, int l) {
if (k > L || l < 0) return 0;
if (i > N) return j == 1 && l == 0;
int& ans = res[i][j][k][l];
if (~ans) return ans;
ans = 0;
int opened = 2*j - 2 + l;
int kk = k + opened * (A[i]-A[i-1]);
// new cc
ans += (long long) (j+1 - 2 + l) * dp(i+1, j+1, kk, l) % mod;
ans %= mod;
ans += l * dp(i+1, j+1, kk, l-1) % mod;
ans %= mod;
if (j > 0) {
// append
ans += (long long) opened * dp(i+1, j, kk, l) % mod;
ans %= mod;
ans += l * dp(i+1, j, kk, l-1) % mod;
ans %= mod;
}
if (j > 1) {
// join
ans += (long long) (j-1) * dp(i+1, j-1, kk, l) % mod;
ans %= mod;
}
//TRACE(i _ j _ k _ l _ ans);
return ans;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> N >> L;
FOR(i,1,N){
cin >> A[i];
}
// corner case -- cannot close both ends simultaneously
if (N == 1) {
cout << 1 << '\n';
return 0;
}
sort(A+1,A+1+N);
memset(res,-1,sizeof res);
cout << dp(1,0,0,2) << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |