#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll nx=105, mx=1005, mod=1e9+7;
ll n, m, h[nx], dp[nx][nx][mx][3], res, c;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m;
for (ll i=1; i<=n; i++) cin>>h[i];
if (n==1) return cout<<1, 0;
sort(h+1, h+n+1);
dp[0][0][0][0]=1;
for (ll i=1; i<n; i++)
{
for (ll j=1; j<=i; j++)
{
for (ll k=0; k<=m; k++)
{
for (ll l=0; l<3; l++)
{
ll x=(h[i+1]-h[i])*(2*j-l);
if (k<x) continue;
dp[i][j][k][l]=dp[i-1][j-1][k-x][l];
if (l>0) dp[i][j][k][l]=(dp[i][j][k][l]+dp[i-1][j-1][k-x][l-1]*(3-l))%mod;
dp[i][j][k][l]=(dp[i][j][k][l]+dp[i-1][j][k-x][l]*(2*j-l))%mod;
if (l>0) dp[i][j][k][l]=(dp[i][j][k][l]+dp[i-1][j][k-x][l-1]*(3-l)*(j-(l-1)))%mod;
if (l==0) dp[i][j][k][l]=(dp[i][j][k][l]+dp[i-1][j+1][k-x][l]*(j+1)*j)%mod;
if (l==1) dp[i][j][k][l]=(dp[i][j][k][l]+dp[i-1][j+1][k-x][l]*j*j)%mod;
if (l==2) dp[i][j][k][l]=(dp[i][j][k][l]+dp[i-1][j+1][k-x][l]*j*(j-1))%mod;
}
}
}
}
for (ll i=0; i<=m; i++) res=(res+dp[n-1][2][i][2]+dp[n-1][1][i][1])%mod;
cout<<res;
}
/*
4 2
1 2 3 4
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
4440 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
3 ms |
16732 KB |
Output is correct |
6 |
Correct |
2 ms |
14684 KB |
Output is correct |
7 |
Correct |
2 ms |
12636 KB |
Output is correct |
8 |
Correct |
2 ms |
16732 KB |
Output is correct |
9 |
Correct |
4 ms |
16728 KB |
Output is correct |
10 |
Correct |
2 ms |
16732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
26972 KB |
Output is correct |
2 |
Correct |
4 ms |
31200 KB |
Output is correct |
3 |
Correct |
5 ms |
31068 KB |
Output is correct |
4 |
Correct |
5 ms |
31068 KB |
Output is correct |
5 |
Correct |
5 ms |
31068 KB |
Output is correct |
6 |
Correct |
5 ms |
31064 KB |
Output is correct |
7 |
Correct |
2 ms |
14940 KB |
Output is correct |
8 |
Correct |
2 ms |
16988 KB |
Output is correct |
9 |
Correct |
2 ms |
17240 KB |
Output is correct |
10 |
Correct |
2 ms |
14940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
4440 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
3 ms |
16732 KB |
Output is correct |
6 |
Correct |
2 ms |
14684 KB |
Output is correct |
7 |
Correct |
2 ms |
12636 KB |
Output is correct |
8 |
Correct |
2 ms |
16732 KB |
Output is correct |
9 |
Correct |
4 ms |
16728 KB |
Output is correct |
10 |
Correct |
2 ms |
16732 KB |
Output is correct |
11 |
Correct |
4 ms |
26972 KB |
Output is correct |
12 |
Correct |
4 ms |
31200 KB |
Output is correct |
13 |
Correct |
5 ms |
31068 KB |
Output is correct |
14 |
Correct |
5 ms |
31068 KB |
Output is correct |
15 |
Correct |
5 ms |
31068 KB |
Output is correct |
16 |
Correct |
5 ms |
31064 KB |
Output is correct |
17 |
Correct |
2 ms |
14940 KB |
Output is correct |
18 |
Correct |
2 ms |
16988 KB |
Output is correct |
19 |
Correct |
2 ms |
17240 KB |
Output is correct |
20 |
Correct |
2 ms |
14940 KB |
Output is correct |
21 |
Correct |
3 ms |
15448 KB |
Output is correct |
22 |
Correct |
75 ms |
75428 KB |
Output is correct |
23 |
Correct |
97 ms |
86356 KB |
Output is correct |
24 |
Correct |
90 ms |
82776 KB |
Output is correct |
25 |
Correct |
101 ms |
84820 KB |
Output is correct |
26 |
Correct |
85 ms |
79700 KB |
Output is correct |
27 |
Correct |
40 ms |
49488 KB |
Output is correct |
28 |
Correct |
47 ms |
55828 KB |
Output is correct |
29 |
Correct |
82 ms |
80724 KB |
Output is correct |
30 |
Correct |
117 ms |
85176 KB |
Output is correct |