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 FOR(i, x, y) for (int i = x; i < y; i++)
int N, L, A[105], md = 1e9 + 7; long long dp[105][105][1005][5], ans;
int main(){
cin >> N >> L;
FOR(i, 1, N + 1) cin >> A[i];
sort(A + 1, A + N + 1); dp[0][0][0][0] = 1;
FOR(i, 0, N + 1) FOR(j, 0, N + 1) FOR(l, 0, L + 1) FOR(m, 0, 3){
int dif = (A[i + 1] - A[i]) * (2 * j - m);
long long &DP = dp[i][j][l][m]; DP %= md;
if (j) dp[i + 1][j - 1][l + dif][m] += DP * (j - 1); //merge
dp[i + 1][j + 1][l + dif][m] += DP * (j + 1 - m); //new
dp[i + 1][j][l + dif][m] += DP * (2 * j - m); //append
dp[i + 1][j][l + dif][m + 1] += DP * (2 - m); //append end
dp[i + 1][j + 1][l + dif][m + 1] += DP * (2 - m); //create end
if (i == N and j == 1 and m == 2) ans += DP, ans %= md;
}
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... |