#include <bits/stdc++.h>
using namespace std;
#define FOR(i,start,end) for(int i=start;i<(int)(end);i++)
#define FORE(i,start,end) for(int i=start;i<=(int)end;i++)
#define RFORE(i,start,end) for(int i = start; i>=end; i--)
#define all(a) a.begin(), a.end()
#define v vector
#define mp make_pair
typedef long long ll;
typedef pair<int, int > pii;
template<class T> void minn(T &a, T b) { a = min(a, b); }
template<class T> void maxx(T &a, T b) { a = max(a, b); }
void io() {
#ifdef LOCAL_PROJECT
freopen("input.in", "r", stdin); freopen("output.out", "w", stdout);
#else
#endif
ios_base::sync_with_stdio(false); cin.tie(NULL);
}
/***************************JOI16_skyscraper*************************************/
int N, a[101], L;
int dp[101][101][3][1001];
/*
# ways to assign [i,N] with total abs <= L
given start with g groups, e ends, sum base value
*/
ll f(int i, int g, int e, int sum) {
sum += (2 * g + e)*(a[i] - a[i - 1]);
if (sum > L) return 0;
if (i == N) {
if (g == 0 && e!=0) return 1;
else return 0;
}
if (dp[i][g][e][sum] == 0) {
ll ret = 0;
// join existing group
if (g > 0 || e > 0) ret += f(i + 1, g, e, sum)*(2 * g + e);
// make new group
ret += f(i + 1, g + 1, e, sum)*(g + 1);
// join two groups or ends
if (g > 0) ret += f(i + 1, g - 1, e, sum)*(e + g - 1);
// make new end, by itself
if (e < 2) ret += f(i + 1, g, e + 1, sum)*(2 - e);
// make new end, joined with a group
if (e < 2 && g>0) ret += f(i + 1, g - 1, e + 1, sum)*(2 - e);
ret %= 1000000007;
if (ret > 0)
dp[i][g][e][sum] = ret;
else
dp[i][g][e][sum] = -1;
}
if (dp[i][g][e][sum] > 0) return dp[i][g][e][sum];
else return 0;
}
int main() {
io();
cin >> N >> L;
if (N == 1) {
cout << 1 << "\n";
return 0;
}
FORE(i, 1, N) cin >> a[i];
sort(a + 1, a + 1 + N);
cout << f(1, 0, 0, 0) << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
484 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
3 ms |
512 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1024 KB |
Output is correct |
2 |
Correct |
2 ms |
768 KB |
Output is correct |
3 |
Correct |
3 ms |
1024 KB |
Output is correct |
4 |
Correct |
2 ms |
768 KB |
Output is correct |
5 |
Correct |
2 ms |
768 KB |
Output is correct |
6 |
Correct |
3 ms |
896 KB |
Output is correct |
7 |
Correct |
2 ms |
640 KB |
Output is correct |
8 |
Correct |
4 ms |
1024 KB |
Output is correct |
9 |
Correct |
4 ms |
1024 KB |
Output is correct |
10 |
Correct |
4 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
484 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
3 ms |
512 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
3 ms |
1024 KB |
Output is correct |
12 |
Correct |
2 ms |
768 KB |
Output is correct |
13 |
Correct |
3 ms |
1024 KB |
Output is correct |
14 |
Correct |
2 ms |
768 KB |
Output is correct |
15 |
Correct |
2 ms |
768 KB |
Output is correct |
16 |
Correct |
3 ms |
896 KB |
Output is correct |
17 |
Correct |
2 ms |
640 KB |
Output is correct |
18 |
Correct |
4 ms |
1024 KB |
Output is correct |
19 |
Correct |
4 ms |
1024 KB |
Output is correct |
20 |
Correct |
4 ms |
768 KB |
Output is correct |
21 |
Correct |
4 ms |
2176 KB |
Output is correct |
22 |
Correct |
112 ms |
19240 KB |
Output is correct |
23 |
Correct |
74 ms |
9180 KB |
Output is correct |
24 |
Correct |
75 ms |
12672 KB |
Output is correct |
25 |
Correct |
50 ms |
9464 KB |
Output is correct |
26 |
Correct |
47 ms |
9592 KB |
Output is correct |
27 |
Correct |
41 ms |
15480 KB |
Output is correct |
28 |
Correct |
66 ms |
17272 KB |
Output is correct |
29 |
Correct |
77 ms |
17372 KB |
Output is correct |
30 |
Correct |
60 ms |
9464 KB |
Output is correct |