#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 12, maxk = 1000, inf = 1000 + 1, mod = 1e9 + 7;
long long n, mx, a[maxn], dp[2][maxn][maxk][3];
int main(){
cin >> n >> mx;
for(int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
for(int i = n; i >= 1; i--)
swap(a[i], a[i - 1]);
a[n + 1] = inf;
//cout << a[1] << ' ' << a[2] << endl;
dp[0][0][0][0] = 1;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
for(int c = 1; c <= mx; c++)
for(int m = 0; m <= 2; m++){
int delta = (2 * j - m) * (a[i + 1] - a[i]);
dp[i & 1][j][c][m] = 0;
if(i == 2)
dp[0][0][0][0] = 0;
if(delta > c)
continue;
dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j - 1][c - delta][m] * (j - m);
if(m > 0){
dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j - 1][c - delta][m - 1] * (2 - (m - 1));
}
dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j][c - delta][m] * (2 * j - m);
if(m > 0)
dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j][c - delta][m - 1] * (3 - m);
dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j + 1][c - delta][m] * (j);
dp[i & 1][j][c][m] %= mod;
// cout << i << ' ' << j + 1 << ' ' << c- delta << ' ' << m <<' ' << dp[i][j + 1][c - delta][m] << endl << endl;
}
long long ans = 0;
for(int c = 1; c <= mx; c++){
ans += dp[n & 1][1][c][2];
ans %= mod;
}
cout << ans << endl;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:28:48: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
28 | dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j - 1][c - delta][m] * (j - m);
| ~~^~~
skyscraper.cpp:32:52: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
32 | dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j - 1][c - delta][m - 1] * (2 - (m - 1));
| ~~^~~
skyscraper.cpp:35:48: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
35 | dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j][c - delta][m] * (2 * j - m);
| ~~^~~
skyscraper.cpp:38:52: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
38 | dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j][c - delta][m - 1] * (3 - m);
| ~~^~~
skyscraper.cpp:40:48: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
40 | dp[i & 1][j][c][m] += dp[i & 1 ^ 1][j + 1][c - delta][m] * (j);
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
436 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
440 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
440 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |