#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 101;
const int MAXL = 1001;
const int MOD = 1e9+7;
int n, l;
int heights[MAXN];
int dp[MAXN][MAXN][MAXL][2][2]; // number of elems, number of cc, value if all other things are next value, left occupied, right occupied
/*
Transitions:
We can create a new cc, add to an existing one, or merge two
New cc:
Rescale all cc boundaries to the next increment
open spaces = cc-1
current value = 2*next-cur elem
this could go in any of the open spaces
*/
void dpa(int &a, int &b) {
a += b;
a %= MOD;
}
void dpa(int &a, ll &b) {
a += b;
a %= MOD;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> l;
for (int i = 0; i < n; i++) cin >> heights[i];
sort(heights, heights+n);
int curv = 2*(heights[1]-heights[0]);;
if (curv <= l) dp[1][1][curv][0][0] = 1;
curv += heights[0]-heights[1];
if (curv <= l) {
dp[1][1][curv][1][0] = 1;
dp[1][1][curv][0][1] = 1;
}
heights[n] = heights[n-1];
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= min(i, n+1-i); j++) {
for (int v = 0; v <= l; v++) {
for (int lo = 0; lo < 2; lo++) {
for (int ro = 0; ro < 2; ro++) {
if (j > 1) {
int bounds = 2*(j-1)-lo-ro;
int ex = (heights[i]-heights[i-1])*bounds+2*heights[i]-2*heights[i-1];
if (ex <= v) {
ll cur = (ll) (j-lo-ro)*dp[i-1][j-1][v-ex][lo][ro];
cur %= MOD;
dpa(dp[i][j][v][lo][ro], cur);
}
int nex = ex;
if (nex <= v) {
if (lo) dpa(dp[i][j][v][lo][ro], dp[i-1][j-1][v-nex][0][ro]);
if (ro) dpa(dp[i][j][v][lo][ro], dp[i-1][j-1][v-nex][lo][0]);
}
}
int bounds = 2*j-lo-ro;
int ex = (heights[i]-heights[i-1])*bounds;
if (ex <= v) {
ll cur = (ll) (2*j-lo-ro)*dp[i-1][j][v-ex][lo][ro];
cur %= MOD;
dpa(dp[i][j][v][lo][ro], cur);
}
int nex = ex;
if (nex <= v) {
if (lo) dpa(dp[i][j][v][lo][ro], dp[i-1][j][v-nex][0][ro]);
if (ro) dpa(dp[i][j][v][lo][ro], dp[i-1][j][v-nex][lo][0]);
}
bounds = 2*j-lo-ro;
ex = (heights[i]-heights[i-1])*bounds;
if (ex <= v) {
ll cur = (ll) (j)*dp[i-1][j+1][v-ex][lo][ro];
cur %= MOD;
dpa(dp[i][j][v][lo][ro], cur);
}
}
}
}
}
}
int ans = 0;
for (int i = 0; i <= l; i++) {
dpa(ans, dp[n][1][i][1][1]);
}
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
588 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
584 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |