#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=103;
const int L=1004;
ll mod=1e9+7;
ll dp[N][L][3];
ll dp_[N][L][3];
ll n,l,d,ans,a[N];
main () {
cin>>n>>l;
if (n==1) {
cout<<1<<endl;
return 0;
}
for (int i=1; i<=n; i++)
cin>>a[i];
sort(a+1,a+n+1);
a[n+1]=100000;
dp_[0][0][0]=1;
for (int i=2; i<=n+1; i++) {
for (int cc=1; cc<=n; cc++) {
for (int p=0; p<=l; p++) {
d=(a[i]-a[i-1])*(2*cc);
if (d<=p) {
dp[cc][p][0]=(dp[cc][p][0]+dp_[cc-1][p-d][0]*cc)%mod;
dp[cc][p][0]=(dp[cc][p][0]+dp_[cc][p-d][0]*2*cc)%mod;
dp[cc][p][0]=(dp[cc][p][0]+dp_[cc+1][p-d][0]*cc)%mod;
}
d=(a[i]-a[i-1])*(2*cc-1);
if (d<=p) {
dp[cc][p][1]=(dp[cc][p][1]+dp_[cc][p-d][0]*2)%mod;
dp[cc][p][1]=(dp[cc][p][1]+dp_[cc-1][p-d][0]*2)%mod;
dp[cc][p][1]=(dp[cc][p][1]+dp_[cc-1][p-d][1]*(cc-1))%mod;
dp[cc][p][1]=(dp[cc][p][1]+dp_[cc][p-d][1]*(2*cc-1))%mod;
dp[cc][p][1]=(dp[cc][p][1]+dp_[cc+1][p-d][1]*cc)%mod;
}
d=(a[i]-a[i-1])*(2*cc-2);
if (d<=p) {
dp[cc][p][2]=(dp[cc][p][2]+dp_[cc][p-d][1])%mod;
dp[cc][p][2]=(dp[cc][p][2]+dp_[cc-1][p-d][1])%mod;
dp[cc][p][2]=(dp[cc][p][2]+dp_[cc-1][p-d][2]*(cc-2))%mod;
dp[cc][p][2]=(dp[cc][p][2]+dp_[cc][p-d][2]*(2*cc-2))%mod;
dp[cc][p][2]=(dp[cc][p][2]+dp_[cc+1][p-d][2]*cc)%mod;
}
if (i==n+1 && cc==1)
ans=(ans+dp[cc][p][2])%mod;
}
}
for (int cc=0; cc<=n; cc++)
for (int p=0; p<=l; p++)
for (int t=0; t<3; ++t)
dp_[cc][p][t]=dp[cc][p][t],dp[cc][p][t]=0;
}
cout<<ans<<"\n";
}
Compilation message
skyscraper.cpp:15:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
15 | main () {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
748 KB |
Output is correct |
6 |
Correct |
3 ms |
748 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
3 ms |
748 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
620 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
748 KB |
Output is correct |
6 |
Correct |
3 ms |
748 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
3 ms |
748 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
1 ms |
620 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
21 |
Correct |
2 ms |
748 KB |
Output is correct |
22 |
Correct |
332 ms |
4068 KB |
Output is correct |
23 |
Correct |
329 ms |
5100 KB |
Output is correct |
24 |
Correct |
299 ms |
4716 KB |
Output is correct |
25 |
Correct |
338 ms |
5228 KB |
Output is correct |
26 |
Correct |
304 ms |
5100 KB |
Output is correct |
27 |
Correct |
112 ms |
2412 KB |
Output is correct |
28 |
Correct |
153 ms |
2668 KB |
Output is correct |
29 |
Correct |
292 ms |
3948 KB |
Output is correct |
30 |
Correct |
340 ms |
5228 KB |
Output is correct |