#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 110;
const int L = 1010;
const int MOD = 1e9+7;
int n, l;
int A[N], dp[N][N][L][3];
bool vis[N][N][L][3];
ll solve(int i, int comp, int val, int ends)
{
if (comp == 0 || val > l || ends == 3) return 0;
if (i == n+1)
return comp==1 && val<=l && ends==2 ? 1 : 0;
if (vis[i][comp][val][ends]) return dp[i][comp][val][ends];
vis[i][comp][val][ends] = true;
int x = val+(2*comp-ends)*(A[i]-A[i-1]);
ll ans = 0;
// add new component
ans = (ans + (comp+1-ends)*solve(i+1, comp+1, x, ends)) % MOD;
// add new component to an end
ans = (ans + (2-ends)*solve(i+1, comp+1, x, ends+1)) % MOD;
// append to any components normally
ans = (ans + (2*comp-ends)*solve(i+1, comp, x, ends)) % MOD;
// append to a component and mark as an end
ans = (ans + (2-ends)*solve(i+1, comp, x, ends+1)) % MOD;
// merge components
ans = (ans + (comp-1)*solve(i+1, comp-1, x, ends)) % MOD;
//printf("dp[%d][%d][%d][%d] = %lld\n", i, comp, val, ends, ans);
return dp[i][comp][val][ends] = ans;
}
int main()
{
scanf("%d%d", &n, &l);
for (int i = 1; i <= n; ++i)
scanf("%d", &A[i]);
sort(A+1, A+n+1);
ll ans = n == 1 ? 1 : (solve(2,1,0,0)+2*solve(2,1,0,1))%MOD;
printf("%lld\n", ans);
return 0;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &l);
~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &A[i]);
~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
740 KB |
Output is correct |
5 |
Correct |
2 ms |
1052 KB |
Output is correct |
6 |
Correct |
2 ms |
1088 KB |
Output is correct |
7 |
Correct |
2 ms |
1088 KB |
Output is correct |
8 |
Correct |
2 ms |
1088 KB |
Output is correct |
9 |
Correct |
2 ms |
1088 KB |
Output is correct |
10 |
Correct |
2 ms |
1088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1488 KB |
Output is correct |
2 |
Correct |
2 ms |
1488 KB |
Output is correct |
3 |
Correct |
2 ms |
1540 KB |
Output is correct |
4 |
Correct |
2 ms |
1540 KB |
Output is correct |
5 |
Correct |
2 ms |
1540 KB |
Output is correct |
6 |
Correct |
3 ms |
1540 KB |
Output is correct |
7 |
Correct |
2 ms |
1540 KB |
Output is correct |
8 |
Correct |
2 ms |
1560 KB |
Output is correct |
9 |
Correct |
3 ms |
1692 KB |
Output is correct |
10 |
Correct |
2 ms |
1692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
740 KB |
Output is correct |
5 |
Correct |
2 ms |
1052 KB |
Output is correct |
6 |
Correct |
2 ms |
1088 KB |
Output is correct |
7 |
Correct |
2 ms |
1088 KB |
Output is correct |
8 |
Correct |
2 ms |
1088 KB |
Output is correct |
9 |
Correct |
2 ms |
1088 KB |
Output is correct |
10 |
Correct |
2 ms |
1088 KB |
Output is correct |
11 |
Correct |
3 ms |
1488 KB |
Output is correct |
12 |
Correct |
2 ms |
1488 KB |
Output is correct |
13 |
Correct |
2 ms |
1540 KB |
Output is correct |
14 |
Correct |
2 ms |
1540 KB |
Output is correct |
15 |
Correct |
2 ms |
1540 KB |
Output is correct |
16 |
Correct |
3 ms |
1540 KB |
Output is correct |
17 |
Correct |
2 ms |
1540 KB |
Output is correct |
18 |
Correct |
2 ms |
1560 KB |
Output is correct |
19 |
Correct |
3 ms |
1692 KB |
Output is correct |
20 |
Correct |
2 ms |
1692 KB |
Output is correct |
21 |
Correct |
5 ms |
2980 KB |
Output is correct |
22 |
Correct |
168 ms |
22440 KB |
Output is correct |
23 |
Correct |
88 ms |
22440 KB |
Output is correct |
24 |
Correct |
98 ms |
22440 KB |
Output is correct |
25 |
Correct |
87 ms |
22440 KB |
Output is correct |
26 |
Correct |
93 ms |
22440 KB |
Output is correct |
27 |
Correct |
48 ms |
22440 KB |
Output is correct |
28 |
Correct |
64 ms |
22440 KB |
Output is correct |
29 |
Correct |
125 ms |
22440 KB |
Output is correct |
30 |
Correct |
85 ms |
22440 KB |
Output is correct |