This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
typedef long long ll;
const ll mod = 1e9 + 7;
ll n, mx, dp[105][105][1005][5], h[101];
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> mx;
for(int i = 1; i <= n; i++) cin >> h[i];
if(n == 1){
cout << "1"; return 0;
}
sort(h + 1, h + n + 1);
dp[0][0][0][0] = 1; h[n + 1] = 10000;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= i; j++)
for(int kk = 0; kk <= mx; kk++)
for(int l = 0; l < 3; l++){
int d = (2 * j - l) * (h[i + 1] - h[i]);
int k = kk + d;
if(k > mx) continue;
if(j > l) dp[i][j][k][l] += (j - l) * dp[i - 1][j - 1][kk][l];
dp[i][j][k][l] += (2 * j - l) * dp[i - 1][j][kk][l];
dp[i][j][k][l] += j * dp[i - 1][j + 1][kk][l];
if(l) {
dp[i][j][k][l] += (3 - l) * dp[i - 1][j - 1][kk][l - 1];
if(i == 2 && j == 1 && k == 5 && l == 1){
//cout << i << ' ' << j << ' ' << kk << ' ' << l - 1 << ' ' << dp[i][j][kk][l - 1] << '\n';
}
dp[i][j][k][l] += (3 - l) * dp[i - 1][j][kk][l - 1];
}
dp[i][j][k][l] %= mod;
//cout << i << ' ' << j << ' ' << k << ' ' << l << ' ' << dp[i][j][k][l] << '\n';
}
ll ans = 0;
for(int i = 0; i <= mx; i++) ans += dp[n][1][i][2], ans %= mod;
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |