#include <bits/stdc++.h>
//#pragma GCC optimize ("03")
#define FastIO ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
#define FILES freopen("in" , "r" , stdin) , freopen("out" , "w" , stdout)
#define ll long long
#define ull unsigned long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define qwerty1 first
#define qwerty2 second
#define qwerty3 -> first
#define qwerty4 -> second
#define umap unordered_map
#define uset unordered_set
#define pii pair < ll , ll >
#define pq priority_queue
#define dbg(x) cerr << #x << ": " << x << '\n'
namespace FastRead
{
char __buff[5000];ll __lg = 0 , __p = 0;
char nc()
{
if(__lg == __p){__lg = fread(__buff , 1 , 5000 , stdin);__p = 0;if(!__lg) return EOF;}
return __buff[__p++];
}
template<class T>void read(T&__x)
{
T __sgn = 1; char __c;while(!isdigit(__c = nc()))if(__c == '-')__sgn = -1;
__x = __c - '0';while(isdigit(__c = nc()))__x = __x * 10 + __c - '0';__x *= __sgn;
}
}
using namespace FastRead;
using namespace std;
const ll N = 1e2 + 10;
const ll L = 1e3 + 10;
const ll M = 1e9 + 7;
const ld PI = acos(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll n , l;
ll a[N] , dp[N][N][L][3];
void add(ll &x , ll y)
{
if(y >= M) y %= M;
x += y;
if(x >= M) x -= M;
}
signed main()
{
// #ifndef ONLINE_JUDGE
// FastIO , FILES;
// #endif
ll i , j , s;
cin >> n >> l;
for(i = 1 ; i <= n ; i++)
cin >> a[i];
if(n == 1)
{
return cout << (a[1] > l ? 0 : 1) , 0;
}
sort(a + 1 , a + n + 1);
a[n + 1] = L;
dp[1][1][0][2] = 1;
if(a[2] - a[1] <= l) dp[1][1][a[2] - a[1]][1] = 2;
if(2 * (a[2] - a[1]) <= l) dp[1][1][2 * (a[2] - a[1])][0] = 1;
for(i = 2 ; i <= n ; i++)
for(j = 1 ; j <= i ; j++)
{
for(s = 0 ; s <= l ; s++)
{
ll delta = a[i + 1] - a[i];
///concat
if(s - 2 * j * delta >= 0)
add(dp[i][j][s][0] , 2 * j * dp[i - 1][j][s - 2 * j * delta][0]);
if(s - (2 * j - 1) * delta >= 0)
add(dp[i][j][s][1] , 2 * dp[i - 1][j][s - (2 * j - 1) * delta][0]);
if(s - (2 * j - 1) * delta >= 0 && 2 * j - 1 >= 0)
add(dp[i][j][s][1] , (2 * j - 1) * dp[i - 1][j][s - (2 * j - 1) * delta][1]);
if(s - (2 * j - 2) * delta >= 0)
add(dp[i][j][s][2] , dp[i - 1][j][s - (2 * j - 2) * delta][1]);
if(s - (2 * j - 2) * delta >= 0 && 2 * j - 2 >= 0)
add(dp[i][j][s][2] , (2 * j - 2) * dp[i - 1][j][s - (2 * j - 2) * delta][2]);
///merge
if(s - 2 * j * delta >= 0)
add(dp[i][j][s][0] , j * dp[i - 1][j + 1][s - 2 * j * delta][0]);
if(s - (2 * j - 1) * delta >= 0)
add(dp[i][j][s][1] , j * dp[i - 1][j + 1][s - (2 * j - 1) * delta][1]);
if(s - (2 * j - 2) * delta >= 0)
add(dp[i][j][s][2] , j * dp[i - 1][j + 1][s - (2 * j - 2) * delta][2]);
///new
if(s - 2 * (j - 1) * delta - 2 * delta >= 0)
add(dp[i][j][s][0] , j * dp[i - 1][j - 1][s - 2 * (j - 1) * delta - 2 * delta][0]);
if(s - 2 * (j - 1) * delta - delta >= 0)
add(dp[i][j][s][1] , 2 * dp[i - 1][j - 1][s - 2 * (j - 1) * delta - delta][0]);
if(2 * (j - 1) - 1 >= 0 && s - (2 * (j - 1) - 1) * delta - 2 * delta >= 0 && j - 1 >= 0)
add(dp[i][j][s][1] , (j - 1) * dp[i - 1][j - 1][s - (2 * (j - 1) - 1) * delta - 2 * delta][1]);
if(2 * (j - 1) - 1 >= 0 && s - (2 * (j - 1) - 1) * delta - delta >= 0)
add(dp[i][j][s][2] , dp[i - 1][j - 1][s - (2 * (j - 1) - 1) * delta - delta][1]);
if(2 * (j - 1) - 2 >= 0 && s - (2 * (j - 1) - 2) * delta - 2 * delta >= 0 && j - 2 >= 0)
add(dp[i][j][s][2] , (j - 2) * dp[i - 1][j - 1][s - (2 * (j - 1) - 2) * delta - 2 * delta][2]);
}
}
ll ans = 0;
for(s = 0 ; s <= l ; s++)
add(ans , dp[n][1][s][2]);
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
704 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
696 KB |
Output is correct |
5 |
Correct |
1 ms |
696 KB |
Output is correct |
6 |
Correct |
1 ms |
828 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |