#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7;
int32_t main()
{
int n, l;
cin >> n >> l;
l++;
vector<int> nums(n);
for (int i = 0; i < n; i++)
{
cin >> nums[i];
}
sort(nums.begin(), nums.end());
vector<vector<vector<vector<int>>>> dp(n+1, vector<vector<vector<int>>>(l, vector<vector<int>>(n+1, vector<int>(3, 0))));
dp[0][0][0][0] = 1;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < l; j++)
{
for (int k = 0; k < n; k++)
{
for (int m =0; m < 3; m++)
{
int nsum = j;
if (k==0 && i) continue;
if(i) nsum = j+(k*2-m)*(nums[i]-nums[i-1]);
if(nsum >= l) continue;
if (nsum<0) continue;
if(k) dp[i+1][nsum][k][m] += dp[i][j][k][m]*(k*2-m);
if(k) dp[i+1][nsum][k-1][m] += dp[i][j][k][m]*(k-1);
if(k+1>m) dp[i+1][nsum][k+1][m] += dp[i][j][k][m]*(k+1-m);
if(m!=2)
{
dp[i+1][nsum][k+1][m+1] += dp[i][j][k][m]*(2-m);
if(k) dp[i+1][nsum][k][m+1] += dp[i][j][k][m]*(2-m);
dp[i+1][nsum][k+1][m+1]%=mod;
dp[i+1][nsum][k][m+1]%=mod;
}
//what are new values of j?
//we add them in increasing order. so any next one added must be
dp[i+1][nsum][k][m]%=mod;
if(k) dp[i+1][nsum][k-1][m]%=mod;
dp[i+1][nsum][k+1][m]%=mod;
}
}
}
}
int sum = 0;
for (int i = 0; i < l; i++)
{
sum += dp[n][i][1][2];
sum%=mod;
}
cout << sum;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
860 KB |
Output is correct |
2 |
Correct |
2 ms |
1628 KB |
Output is correct |
3 |
Correct |
1 ms |
856 KB |
Output is correct |
4 |
Correct |
2 ms |
1712 KB |
Output is correct |
5 |
Correct |
2 ms |
1712 KB |
Output is correct |
6 |
Correct |
2 ms |
1628 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
860 KB |
Output is correct |
9 |
Correct |
2 ms |
1372 KB |
Output is correct |
10 |
Correct |
2 ms |
1372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |